文章出處

http://acm.hdu.edu.cn/showproblem.php?pid=4011

就是“簡單”的模擬題, 但是細節較多些。

 1 #include<iostream>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     long long ans;
 7     int n, a, b;
 8     int t1, t2, T;
 9     scanf("%d", &T);
10     for(int k=1; k<=T; k++)
11     {
12         scanf("%d%d%d", &n, &a, &b);
13         ans = a+b;
14         scanf("%d", &t1);
15         for(int i=1; i<n; i++)
16         {
17             scanf("%d", &t2);
18             if((t2-t1-1)*b>2*a) ans += 2*a+b;
19             else ans+=b*(t2-t1);
20             t1=t2;
21         }
22         ans+=a;
23         printf("Case #%d: %I64d\n", k, ans);
24     }
25     return 0;
26 }
View Code

 

 http://acm.hdu.edu.cn/showproblem.php?pid=2094

這個題怎么說呢,不算是模擬題, 但是我又無法給它分類, 也沒用什么高級的算法, 只需要一點機智! 。 排兩次序, 就妥妥的啦。

思路: 獲勝者一定是不會再失敗的名單里的。 而且只有一個冠軍。

#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    string s1[2005], s2[1005];
    int n, t, k;
    while(scanf("%d", &n)!=EOF, n)
    {
        t = 0; k = 0;
        {
            for(int i=0; i<n; i++)
                cin>>s1[i]>>s2[i];
            for(int i=n; i<2*n; i++)
                s1[i] = s2[i-n];
            sort(s1, s1+2*n);
            sort(s2, s2+n);
            for(int i=0; i<2*n-1; i++)
            {
                if(s1[i+1]!=s1[i]) t++;
            }
            for(int i=0; i<n-1; i++)
            {
                if(s2[i+1]!=s2[i]) k++;
            }
            if(t-k==1) printf("Yes\n");
            else printf("No\n");
        }
        return 0;
    }
}
View Code

 


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()