hdu,hduacm

來源:互聯網
上載者:User

hdu,hduacm

題意:N個隊(N <= 100000),每個隊有個總分ai(ai <= 1000000),每場比賽比賽雙方最多各可獲得1分,問最少經過了多少場比賽。

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=4974

——>>我們應該盡量使每場比賽的得分為1 : 1,這樣可以達到最少的比賽場數(不小於單個隊伍的分數)。

假設有2場比賽的比分為1 : 0,

1)a : b = 1 : 0,c : d = 1 : 0,這時可以安排a : c = 1 : 1,只需1場就可達到相同的分數。

2)a : b = 1 : 0,a : c = 1 : 0,取另外一場比賽d : e = 1 : 1,這時可安排a : d = 1 : 1,a : e = 1 : 1,只需2場就可達到相同的分數。

因此,沒有最多有1場比賽的比分為 1 : 0,其他比賽的比分都為 1 : 1,因此,結果 = max(單個隊伍最高分數, (所有分數和 + 1) / 2)。。。(注意範圍:10 ^ 5 * 10 ^ 6 > 2 ^ 31 - 1)

virtual contest上提交必須開輸入掛才不會TLE。。

hdu題庫4974中 scanf 就可以AC。。

#include <cstdio>int ReadInt(){    int ret = 0;    char ch;    while ((ch = getchar()) && ch >= '0' && ch <= '9')    {        ret = ret * 10 + ch - '0';    }    return ret;}int main(){    int T, N, a, kase = 0;    scanf("%d", &T);    getchar();    while (T--)    {        long long sum = 0;        long long ret = 0;        N = ReadInt();        while (N--)        {            a = ReadInt();            sum += a;            if (a > ret)            {                ret = a;            }        }        if (sum & 1)        {            sum++;        }        sum >>= 1;        if (sum > ret)        {            ret = sum;        }        printf("Case #%d: %I64d\n", ++kase, ret);    }    return 0;}



hdu acm 2032

我發我的ac代碼給你看吧,肯定是輸出時多了什麼空格什麼的,好好看看吧,加油
#include<stdio.h>
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int a[31][31];
int i,j,k;
for(i=1;i<=30;i++)
a[i][1]=a[i][i]=1;
if(n==1)printf("1\n");
if(n>=2)printf("1\n1 1\n");
for(i=3;i<=n;i++)
{
printf("1 ");
for(j=2;j<i;j++)
{
a[i][j]=a[i-1][j]+a[i-1][j-1];
printf("%d ",a[i][j]);
}
printf("%d\n",a[i][i]);
}
printf("\n");
}
}
 
HDU 2000號題

看了代碼,就是輸入3個char字元,從小到大 輸出他。
char字元也是整型數字!
看下MSDN,中scanf的格式要與後面的參數類型和數目對應,否則結果未定義。
其格式和printf一樣的,請看MSDN
scanf("%c%c%c",&a,&b,&c) 3個%C對應&a,&b,&c沒問題的!
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.