随笔-10  评论-1  文章-0  trackbacks-0
Problem A
http://www.codeforces.com/contest/143/problem/A

简单的数学求和,循环解决
  1. #include <stdio.h>

  2. int main()
  3. {
  4.         int r1,r2,c1,c2,d1,d2,a,b,c,d;
  5.         scanf("%d %d %d %d %d %d",&r1,&r2,&c1,&c2,&d1,&d2);
  6.         for (a=1;a<=9;a++)
  7.         {
  8.                 b=r1-a;c=c1-a;d=d1-a;
  9.                 if (b+d==c2&&c+d==r2&&b+c==d2&&a!=b&&a!=c&&a!=d&&b!=c&&b!=d&&c!=d&&b>=1&&b<=9&&c>=1&&c<=9&&d>=1&&d<=9)
  10.                 {
  11.                         printf("%d %d\n%d %d\n",a,b,c,d);
  12.                         return 0;
  13.                 }
  14.         }
  15.         printf("-1\n");
            return 0; 
  16. }

Problem B
http://www.codeforces.com/contest/143/problem/B
字符串处理题,注重细节
  1. #include <stdio.h>
  2. #include <string.h>

  3. char s[110];

  4. int main()
  5. {
  6.         int n,i,flag=0,c=0;
  7.         scanf("%s",s);
  8.         n=strlen(s);
  9.         if (s[0]=='-'){flag=1;printf("(");}
  10.         printf("$");
  11.         for (c=flag;c<n&&s[c]!='.';c++);
  12.         for (i=flag;i<c;i++)
  13.         {
  14.                 if (i!=flag&&(c-i)%3==0)printf(",");
  15.                 printf("%c",s[i]);
  16.         }
  17.         printf(".");
  18.         if (s[c]=='.'&&c+1<n)printf("%c",s[c+1]);
  19.         else printf("0");
  20.         if (s[c]=='.'&&c+2<n)printf("%c",s[c+2]);
  21.         else printf("0");
  22.         if (flag)printf(")");
  23.         printf("\n");
  24. }

Problem C 
http://www.codeforces.com/contest/143/problem/C
Dp解决

  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;


  4. void gao(long long n,long long &a,long long &b)
  5. {
  6.         long long abs=n+1;
  7.         int sqn=sqrt(n);
  8.         for(long long i=sqn;i>=1;i--)
  9.                 if(n%i==0)
  10.                 {
  11.                         a=i;b=n/i;
  12.                         break;
  13.                 }
  14. }


  15. int main()
  16. {
  17.         long long N;
  18.         cin>>N;
  19.         long long mi,ma;
  20.         ma=(N+1)*3LL*3-N;
  21.         long long n1=N,n2=1;
  22.         int up=sqrt(N);
  23.         for(int i=up;i>=1;i--)
  24.                 if(N%i==0)
  25.                 {
  26.                         gao(N/i,n1,n2);
  27.                         if(mi>(i+1)*(n1+2)*(n2+2)-N)
  28.                                 mi=(i+1)*(n1+2)*(n2+2)-N;
  29.                 }
  30.         cout<<mi<<" "<<ma<<endl;
  31.         return 0;
  32. }
posted on 2012-01-13 02:05 玉香 阅读(186) 评论(0)  编辑 收藏 引用 所属分类: CodeForces

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理