1 #include <stdio.h> 2 #include<math.h> 3 int tr(int x,int y,int z) 4 { 5 if(x+y>z&&y+z>x&&x+z>y&&abs(x-y)<z&&abs(y-z)<x&&abs(x-z)<y) 6 return 1; 7 else 8 return 0; 9 } 10 int tq(int x,int y,int z) 11 { 12 if(x == 0||y==0||z==0||x==y+z||y==x+z||z == x+y) 13 return 1; 14 else 15 return 0; 16 } 17 int main() 18 { 19 int a, b, c, d, i, j,flag = 0; 20 scanf("%d%d%d%d", &a, &b, &c,&d); 21 if(tr(a,b,c)||tr(a,c,d)||tr(b,c,d)||tr(a,b,d)) 22 { 23 flag = 1; 24 printf("TRIANGLE\n"); 25 } 26 if(!flag) 27 { 28 if(tq(a,b,c)||tq(a,c,d)||tq(b,c,d)||tq(a,b,d)) 29 { 30 flag = 1; 31 printf("SEGMENT\n"); 32 } 33 } 34 if(!flag) 35 printf("IMPOSSIBLE\n"); 36 return 0; 37 }
A - A
Description
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input
The input contains three positive integer numbers in the first line: n, m and a (1 ≤ n, m, a ≤ 109).
Output
Write the needed number of flagstones.
Sample Input
6 6 4
4
这题因为数据类型定义的小错了好几次 蛮悲催的
1 #include <stdio.h> 2 int main() 3 { 4 long long n, m, a,x,y; 5 scanf("%lld%lld%lld", &n, &m, &a); 6 if(n%a!=0) 7 x= n/a+1; 8 else 9 x= n/a; 10 if(m%a!=0) 11 y= m/a+1; 12 else 13 y= m/a; 14 printf("%lld\n",x*y); 15 return 0; 16 }
Description
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square t. As the king is not in habit of wasting his time, he wants to get from his current position s to square t in the least number of moves. Help him to do this.
In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
Input
The first line contains the chessboard coordinates of square s, the second line — of square t.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
Output
In the first line print n — minimum number of the king's moves. Then in n lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.
Sample Input
a8
h1
7
RD
RD
RD
RD
RD
RD
RD
这题。。。。这几天搜索做多了 看见直接用BFS 写完2000多行 却发现没办法输出路径,。。纠结 看到别人用很少代码就过了 仔细一看题意 不用那么麻烦
直接枚举各种情况
1 #include <stdio.h> 2 #include<string.h> 3 #include<math.h> 4 void pi(int d1,int d2) 5 { 6 int i; 7 if(d1>0&&d2>0) 8 for(i = 1 ; i <= d1 ; i++) 9 printf("RU\n"); 10 if(d1>0&&d2<0) 11 for(i = 1 ; i <= d1 ; i++) 12 printf("LU\n"); 13 if(d1<0&&d2>0) 14 for(i = 1 ; i <= d2 ; i++) 15 printf("RD\n"); 16 if(d1<0&&d2<0) 17 for(i = 1 ; i <= abs(d1) ; i++) 18 printf("LD\n"); 19 } 20 int main() 21 { 22 int b[2],c[2],i,j,d1,d2; 23 char a[2]; 24 scanf("%c%d%*c",&a[0],&b[0]); 25 scanf("%c%d",&a[1],&b[1]); 26 c[0] = a[0]-96; 27 c[1] = a[1]-96; 28 d2 = c[1]-c[0]; 29 d1 = b[1]-b[0]; 30 if(abs(d1) == abs(d2)) 31 { 32 printf("%d\n",abs(d1)); 33 pi(d1,d2); 34 } 35 else 36 { 37 if(abs(d1)-abs(d2)>0) 38 { 39 printf("%d\n",abs(d1)); 40 for(i = 1 ; i <= abs(d1)-abs(d2);i++) 41 if(d1>0) 42 printf("U\n"); 43 else 44 printf("D\n"); 45 if(d1<0) 46 pi(-abs(d2),d2); 47 else 48 pi(abs(d2),d2); 49 } 50 else 51 { 52 printf("%d\n",abs(d2)); 53 for(i = 1 ; i <= abs(d2)-abs(d1);i++) 54 if(d2>0) 55 printf("R\n"); 56 else 57 printf("L\n"); 58 if(d2>0) 59 pi(d1,abs(d1)); 60 else 61 pi(d1,-abs(d1)); 62 } 63 } 64 return 0; 65 }
Description
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
Output
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Sample Input
4 2 1 3
TRIANGLE
7 2 2 4
SEGMENT
3 5 9 1
IMPOSSIBLE
知道退化三角形是什么 就会做了 满足这两个条件之一 有一条边为0 ;一条边是另外两条的和
1 #include <stdio.h> 2 #include<math.h> 3 int tr(int x,int y,int z) 4 { 5 if(x+y>z&&y+z>x&&x+z>y&&abs(x-y)<z&&abs(y-z)<x&&abs(x-z)<y) 6 return 1; 7 else 8 return 0; 9 } 10 int tq(int x,int y,int z) 11 { 12 if(x == 0||y==0||z==0||x==y+z||y==x+z||z == x+y) 13 return 1; 14 else 15 return 0; 16 } 17 int main() 18 { 19 int a, b, c, d, i, j,flag = 0; 20 scanf("%d%d%d%d", &a, &b, &c,&d); 21 if(tr(a,b,c)||tr(a,c,d)||tr(b,c,d)||tr(a,b,d)) 22 { 23 flag = 1; 24 printf("TRIANGLE\n"); 25 } 26 if(!flag) 27 { 28 if(tq(a,b,c)||tq(a,c,d)||tq(b,c,d)||tq(a,b,d)) 29 { 30 flag = 1; 31 printf("SEGMENT\n"); 32 } 33 } 34 if(!flag) 35 printf("IMPOSSIBLE\n"); 36 return 0; 37 }
Description
Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than minTimei and not more than maxTimei hours per each i-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.
So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours sumTime spent him on preparation, and now he wants to know if he can show his parents a timetable sсhedule with d numbers, where each number sсhedulei stands for the time in hours spent by Peter each i-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all schedulei should equal to sumTime.
Input
The first input line contains two integer numbers d, sumTime (1 ≤ d ≤ 30, 0 ≤ sumTime ≤ 240) — the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following d lines contains two integer numbers minTimei, maxTimei (0 ≤ minTimei ≤ maxTimei ≤ 8), separated by a space — minimum and maximum amount of hours that Peter could spent in the i-th day.
Output
In the first line print YES, and in the second line print d numbers (separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them.
Sample Input
1 48
5 7
NO
2 5
0 1
3 5
YES
1 4
这题蛮水 sum在所有最小的之和 与所有最大之和之间 就YES 之后输出一种情况 具体看代码 吧
1 #include<stdio.h> 2 int main() 3 { 4 int d, t, min[50],max[50],min1 = 0,max1 = 0,i; 5 scanf("%d%d", &d, &t); 6 for(i = 1 ; i <= d ; i++) 7 { 8 scanf("%d%d", &min[i],&max[i]); 9 min1+=min[i]; 10 max1+=max[i]; 11 } 12 if(t>=min1&&t<=max1) 13 { 14 printf("YES\n"); 15 int x = t-min1; 16 for(i = 1 ; i <= d ; i++) 17 { 18 if(i!=1) 19 printf(" "); 20 if(x+min[i]<=max[i]) 21 { 22 printf("%d",x+min[i]); 23 x = 0; 24 } 25 else 26 { 27 printf("%d",max[i]); 28 x-=(max[i]-min[i]); 29 } 30 } 31 } 32 else 33 printf("NO\n"); 34 return 0; 35 }
Description
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment in the shortest possible time. Good luck!
Input
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
Output
Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
Sample Input
This is
Codeforces
Beta
Round
5
************
* This is *
* *
*Codeforces*
* Beta *
* Round *
* 5 *
************
welcome to the
Codeforces
Beta
Round 5
and
good luck
****************
*welcome to the*
* Codeforces *
* Beta *
* Round 5 *
* *
* and *
* good luck *
****************
1 #include<stdio.h> 2 #include<string.h> 3 char c[1001][1001]; 4 int main() 5 { 6 int k[1001], i = 0, j,flag = 1,max = 0,q; 7 while(gets(c[i])!=NULL) 8 { 9 if(c[i][0] == '*') 10 break; 11 k[i] = strlen(c[i]); 12 if(max<k[i]) 13 max = k[i]; 14 i++; 15 } 16 for(j = 1 ; j <= max+2 ; j++) 17 printf("*"); 18 puts(""); 19 for(j = 0 ; j < i ; j++) 20 { 21 printf("*"); 22 if((max-k[j])%2 == 0) 23 { 24 for(q = 1 ;q<=(max-k[j])/2 ; q++) 25 printf(" "); 26 for(q = 0 ; q < k[j] ; q++) 27 printf("%c",c[j][q]); 28 for(q = 1 ;q<=(max-k[j])/2 ; q++) 29 printf(" "); 30 } 31 else 32 { 33 if(flag == 1) 34 { 35 for(q = 1 ;q<=(max-k[j])/2 ; q++) 36 printf(" "); 37 for(q = 0 ; q < k[j] ; q++) 38 printf("%c",c[j][q]); 39 for(q = 1 ;q<=(max-k[j])/2+1 ; q++) 40 printf(" "); 41 flag = 0; 42 } 43 else 44 { 45 for(q = 1 ;q<=(max-k[j])/2+1 ; q++) 46 printf(" "); 47 for(q = 0 ; q < k[j] ; q++) 48 printf("%c",c[j][q]); 49 for(q = 1 ;q<=(max-k[j])/2 ; q++) 50 printf(" "); 51 flag = 1; 52 } 53 } 54 printf("*\n"); 55 } 56 for(j = 1 ; j <= max+2 ; j++) 57 printf("*"); 58 return 0; 59 }