Problem 1001  HDU4350 Card

代码:

View Code 
 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 using namespace std;
 5 int main()
 6 {
 7     int a,t,i,n,m,k,num,cas=0;
 8     int b[53],c[101];
 9     scanf("%d",&t);
10     while(t--)
11     {
12         cas++;
13         num=0;
14         a=1;
15         for(i=1;i<=52;i++)
16             scanf("%d",&b[i]);
17         scanf("%d%d%d",&n,&m,&k);    
18         while(a!=1||!num)
19         {
20             a=(a+k-m+1)%k;
21             if(a==0)
22                 a=k;
23             c[++num]=a;
24         }
25         printf("Case #%d: ",cas);
26         n%=num;
27         if(!n)
28         {
29             printf("%d",b[1]);
30             for(i=2;i<=52;i++)
31                 printf(" %d",b[i]);
32         }
33         else
34         {
35             int pos=k-c[n]+2;
36             printf("%d",b[pos]);
37             for(i=pos+1;i<=k;i++)
38                 printf(" %d",b[i]);
39             for(i=1;i<pos;i++)
40                 printf(" %d",b[i]);
41             for(i=k+1;i<=52;i++)
42                 printf(" %d",b[i]);
43         }
44         puts("");
45     }
46     return 0;
47 }
48

 


Problem 1006  HDU4355 Party All the Time

三分查找模版

代码: 

View Code 
 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <cmath>
 5 const int N=50001;
 6 struct node
 7 {
 8     double x;
 9     double w;
10 }p[N];
11 int n;
12 double getsum(double mid)
13 {
14     int i;
15     double s,sum=0.00;
16     for(i=0;i<n;i++)
17     {
18         s=fabs(p[i].x-mid);
19         sum+=s*s*s*p[i].w;
20     }
21     return sum;
22 }
23 int main()
24 {
25     int t,i,k=0;
26     double min,max,start,end,mid1,mid2,a1,a2,a3,a4;
27     scanf("%d",&t);
28     while(t--)
29     {
30         k++;
31         scanf("%d",&n);
32         for(i=0;i<n;i++)
33         {
34             scanf("%lf%lf",&p[i].x,&p[i].w);
35             if(!i)
36                 max=min=p[i].x;
37             if(max<p[i].x)
38                 max=p[i].x;
39             if(min>p[i].x)
40                 min=p[i].x;
41         }
42         start=min;
43         end=max;
44         while(start+0.000001<end)
45         {
46             mid1=(start+end)/2;
47             mid2=(end +mid1)/2;
48             a1=getsum(start);
49             a2=getsum(end);
50             a3=getsum(mid1);
51             a4=getsum(mid2);
52             if(a3<=a4)
53                 end=mid2;
54             else
55                 start=mid1;
56         }
57         min=getsum(start);
58         printf("Case #%d: %I64d\n",k,(long long)(min+0.5));
59     }
60     return 0;
61 }
62

 

 

Problem 1008  HDU4357 String Change 

代码:

 

View Code 
 1 #include <algorithm>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <cstdio>
 5 using namespace std;
 6 const int N=101;
 7 char s1[N];
 8 char s2[N];
 9 int main()
10 {
11     int t,i,k=0,sum1,sum2;
12     scanf("%d",&t);
13     while(t--)
14     {
15         k++;
16         sum1=sum2=0;
17         scanf("%s%s",s1,s2);
18         int flag=0;
19         if(strlen(s1)==2)
20         {
21             for(i=0;i<26;i++)
22             {
23                 if(s1[0]++=='z')
24                     s1[0]='a';
25                 if(s1[1]++=='z')
26                     s1[1]='a';
27                 swap(s1[0],s1[1]);
28                 if(!strcmp(s1,s2))
29                 {
30                     flag=1;
31                     break;
32                 }
33             }
34         }
35         else
36         {
37             for(i=0;i<strlen(s1);i++)
38             {
39                 sum1+=(s1[i]-'a');
40                 sum2+=(s2[i]-'a');
41             }
42             if(!((sum2-sum1)&1))
43                 flag=1;
44         }
45         printf("Case #%d: ",k);
46         if(flag)
47             puts("YES");
48         else
49             puts("NO");
50     }
51     return 0;
52 }
53

 

 

 

 


 

附:

官方题解: 


 

 

 

 

 

 

 、

 

 

 

 

 

 

 

 

 

 

posted on 2012-08-09 19:23  pony1993  阅读(428)  评论(0编辑  收藏  举报

View My Stats