Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2×2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1≤r1,r2,c1,c2,d1,d2≤20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
3 7 4 6 5 5 11 10 13 8 5 16
1 2 3 4 4 7 9 1
#include <stdio.h> int main() { int r1,r2,c1,c2,d1,d2; double a,b,c,d; while(scanf("%d%d%d%d%d%d",&r1,&r2,&c1,&c2,&d1,&d2)==6) { double aa,bb,cc,dd,aaa,bbb,ccc,ddd; if(r1-d1>0) { b=(r1-d1+c2)/2; a=r1-b; c=c1-a; d=c2-b; } else { d=(d1-r1+c2)/2; b=c2-d; a=r1-b; c=r2-d; } if(d2-c1>0) { bb=(d2-c1+r1)/2; aa=r1-bb; dd=c2-bb; cc=r2-dd; } else { cc=(c1-d2+r1)/2; dd=r2-cc; aa=c1-cc; bb=c2-dd; } if(r2-c2>0){ ccc=(r2-c2+d2)/2; ddd=r2-ccc; aaa=c1-ccc; bbb=c2-ddd; } else { bbb=(c2-r2+d2)/2; aaa=r1-bbb; ddd=c2-bbb; ccc=r2-ddd; } if(a==aa&&c==ccc&&d==ddd&&bb==bbb&&a>0&&b>0&&c>0&&d>0) { printf("%.0lf %.0lf\n",a,b); printf("%.0lf %.0lf\n",c,d); } else printf("-1\n"); } return 0; }
Time Limit: 1000MS | Memory Limit: 65535KB | 64bit IO Format: %I64d & %I64u |
[Submit] [Go Back] [Status]
Description
The Super Duper Secret Meeting of the Super Duper Secret Military Squad takes place in a Super Duper Secret Place. The place is an infinite plane with introduced Cartesian coordinate system. The meeting table is represented as a rectangle whose sides are parallel to the coordinate axes and whose vertexes are located at the integer points of the plane. At each integer point which belongs to the table perimeter there is a chair in which a general sits.
Some points on the plane contain radiators for the generals not to freeze in winter. Each radiator is characterized by the number ri — the radius of the area this radiator can heat. That is, if the distance between some general and the given radiator is less than or equal to ri, than the general feels comfortable and warm. Here distance is defined as Euclidean distance, so the distance between points (x1, y1) and (x2, y2) is
Each general who is located outside the radiators' heating area can get sick. Thus, you should bring him a warm blanket. Your task is to count the number of warm blankets you should bring to the Super Duper Secret Place.
The generals who are already comfortable do not need a blanket. Also the generals never overheat, ever if they are located in the heating area of several radiators. The radiators can be located at any integer points on the plane, even inside the rectangle (under the table) or on the perimeter (directly under some general). Even in this case their radius does not change.
Input
Output
Sample Input
2 5 4 2 3 3 1 2 5 3 1 1 3 2 5 2 6 3 2 6 2 2 6 5 3
Sample Output
4 0
题意:一个飞机上的座位需要供热,首先给出两点的坐标是矩形的对角点,对这个矩形的每隔1个单位都有一个座位,给出几个供热源的坐标及供热半径,求其有多少个座位供不到热。 用结构体存需要供热的点,加一个判断是否以供热的变量。然后用点到点的距离是否小于半径求出即可。代码:
#include <cstdio> #include <cmath> #define dis(x1,y1,x2,y2) sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) struct Node //存放边上椅子的点 { int x,y; //点的坐标 bool ok; //是否已被覆盖 }; Node point[100005]; int main() { int a,b,c,d; while(~scanf("%d%d%d%d",&a,&b,&c,&d)) { if(a>c) { int t=a;a=c;c=t; } int j=0; for(int i=a;i<=c;i++) { point[j].x=i;point[j].y=b;point[j++].ok=false; point[j].x=i;point[j].y=d;point[j++].ok=false; } if(b>d) { int t=b;b=d;d=t; } for(int i=b+1;i<d;i++) { point[j].x=a;point[j].y=i;point[j++].ok=false; point[j].x=c;point[j].y=i;point[j++].ok=false; } int n,count=0; double ax,ay,r; scanf("%d",&n); while(n--) { scanf("%lf%lf%lf",&ax,&ay,&r); for(int i=0;i<j;i++) { // printf("%d %d\n",point[i].x,point[i].y); // printf("%lf ",dis(point[i].x,point[i].y,ax,ay)); if(!point[i].ok&&r>=dis(point[i].x,point[i].y,ax,ay)) {count++;point[i].ok=true; } } } printf("%d\n",j-count); } return 0; }
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
The first input line contains the only integer n (2≤n≤100) which represents the number of soldiers in the line. The second line contains integers a1,a2,...,an(1≤ai≤100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers a1,a2,...,an are not necessarily different.
Print the only integer the minimum number of seconds the colonel will need to form a line-up the general will like.
4 33 44 11 22 7 10 10 58 31 63 40 76
2 10
#include <stdio.h> #include <cstring> int a[500]; int main() { int n,min,mini,max,maxi,tmp; while(~scanf("%d",&n)) { if(0>=n) continue; int count; memset(a,0,sizeof(a)); max=-999999;min=999999; for(int i=1;i<=n;i++) { scanf("%d",&tmp); a[i]=tmp; if(tmp>max) { max=tmp; maxi=i; } if(min>=tmp) { min=tmp; mini=i; } } if(mini<maxi) { count=n-mini+maxi-2; } else if(mini==maxi) count=0; else { if(maxi==1) count=n-mini; else if(mini==n) count=maxi-1; else count=n-mini+maxi-1; } printf("%d\n",count); } return 0; }
Time Limit: 2000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
[Submit] [Go Back] [Status]
Description
For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more easily readable format. However, as time went by, the economy of the Far Far Away developed and the scale of operations grew. So the King ordered to found the Bank of Far Far Away and very soon even the rounding didn't help to quickly determine even the order of the numbers involved in operations. Besides, rounding a number to an integer wasn't very convenient as a bank needed to operate with all numbers with accuracy of up to 0.01, and not up to an integer.
The King issued yet another order: to introduce financial format to represent numbers denoting amounts of money. The formal rules of storing a number in the financial format are as follows:
For example, by the above given rules number 2012 will be stored in the financial format as "$2,012.00" and number -12345678.9 will be stored as "($12,345,678.90)".
The merchants of Far Far Away visited you again and expressed much hope that you supply them with the program that can convert arbitrary numbers to the financial format. Can you help them?
Input
The input contains a number that needs to be converted into financial format. The number's notation length does not exceed 100 characters, including (possible) signs "-" (minus) and "." (decimal point). The number's notation is correct, that is:
Output
Print the number given in the input in the financial format by the rules described in the problem statement.
Sample Input
2012
$2,012.00
0.000
$0.00
-0.00987654321
($0.00)
-12345678.9
($12,345,678.90)
Hint
Pay attention to the second and third sample tests. They show that the sign of a number in the financial format (and consequently, the presence or absence of brackets) is determined solely by the sign of the initial number. It does not depend on the sign of the number you got after translating the number to the financial format.
#include <cstdio> #include <iostream> #include <string> using namespace std; int main() { string s1,s2,s3,s4; while(cin>>s1) { s2=s3=s4=""; bool ok=false,flag=false,tc=false; if(s1[0]=='-') tc=true; for(int i=0;i<s1.size();i++) { if(s1[i]=='.') { ok=true; } if(s1[i]>='0'&&s1[i]<='9') { if(s1[i]=='0'&&flag==false&&ok==false){continue;} else { flag=true; if(ok) s3+=s1[i]; else s2+=s1[i]; } } } if(tc) cout<<"("; cout<<"$"; if(s2.size()==0) cout<<"0"; else { for(int i=0;i<s2.size();i++) { if((s2.size()-i)%3==0){ if(i!=0) cout<<","; } cout<<s2[i]; } } cout<<"."; for(int i=0;i<2;i++) { if(s3[i]) cout<<s3[i]; else cout<<"0"; }if(tc) cout<<")"; cout<<endl; } return 0; }
1 S 08:10 2 S 08:35 1 E 10:00 2 E 13:16 0 S 17:00 0 S 17:00 3 E 08:10 1 S 08:20 2 S 09:00 1 E 09:20 0 E 17:00 -1
2 196 0 0 1 60
#include <cstdio> #include <cstring> int cnt; double sum; struct BOAT { int time; bool status; }b[105]; void Init() { sum=0; cnt=0; } int main() { int ind=0,i,j; int h,m; char t[10]; char status; Init(); for(i=1;i<=100;i++) b[i].status=false; while(true) { scanf("%d",&ind); if(ind==-1) break; getchar(); status=getchar(); scanf("%d:%d",&h,&m); if(ind==0) { if(cnt) printf("%d %.0lf\n",cnt,sum/cnt); else printf("0 0\n"); Init(); continue; } if(status=='S') b[ind].time=h*60+m,b[ind].status=true; else { if(b[ind].status) { sum+=h*60+m-b[ind].time; cnt++; b[ind].status=false; } } } }