Problem A
http://www.codeforces.com/contest/143/problem/A
简单的数学求和,循环解决
- #include <stdio.h>
- int main()
- {
- int r1,r2,c1,c2,d1,d2,a,b,c,d;
- scanf("%d %d %d %d %d %d",&r1,&r2,&c1,&c2,&d1,&d2);
- for (a=1;a<=9;a++)
- {
- b=r1-a;c=c1-a;d=d1-a;
- 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)
- {
- printf("%d %d\n%d %d\n",a,b,c,d);
- return 0;
- }
- }
- printf("-1\n");
return 0; - }
Problem B
- #include <stdio.h>
- #include <string.h>
- char s[110];
- int main()
- {
- int n,i,flag=0,c=0;
- scanf("%s",s);
- n=strlen(s);
- if (s[0]=='-'){flag=1;printf("(");}
- printf("$");
- for (c=flag;c<n&&s[c]!='.';c++);
- for (i=flag;i<c;i++)
- {
- if (i!=flag&&(c-i)%3==0)printf(",");
- printf("%c",s[i]);
- }
- printf(".");
- if (s[c]=='.'&&c+1<n)printf("%c",s[c+1]);
- else printf("0");
- if (s[c]=='.'&&c+2<n)printf("%c",s[c+2]);
- else printf("0");
- if (flag)printf(")");
- printf("\n");
- }
Problem C
http://www.codeforces.com/contest/143/problem/C
Dp解决
- #include <iostream>
- #include <cmath>
- using namespace std;
- void gao(long long n,long long &a,long long &b)
- {
- long long abs=n+1;
- int sqn=sqrt(n);
- for(long long i=sqn;i>=1;i--)
- if(n%i==0)
- {
- a=i;b=n/i;
- break;
- }
- }
- int main()
- {
- long long N;
- cin>>N;
- long long mi,ma;
- ma=(N+1)*3LL*3-N;
- long long n1=N,n2=1;
- int up=sqrt(N);
- for(int i=up;i>=1;i--)
- if(N%i==0)
- {
- gao(N/i,n1,n2);
- if(mi>(i+1)*(n1+2)*(n2+2)-N)
- mi=(i+1)*(n1+2)*(n2+2)-N;
- }
- cout<<mi<<" "<<ma<<endl;
- return 0;
- }
posted on 2012-01-13 02:05
玉香 阅读(198)
评论(0) 编辑 收藏 引用 所属分类:
CodeForces