Alice and Bob
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 140 Accepted Submission(s): 99
题目链接:传送门 Problem Description Bob and Alice got separated in the Square, they agreed that if they get separated, they'll meet back at the coordinate point (x, y). Unfortunately they forgot to define the origin of coordinates and the coordinate axis direction. Now, Bob in the lower left corner of the Square, Alice in the upper right corner of the the Square. Bob regards the lower left corner as the origin of coordinates, rightward for positive direction of axis X, upward for positive direction of axis Y. Alice regards the upper right corner as the origin of coordinates, leftward for positive direction of axis X, downward for positive direction of axis Y. Assuming that Square is a rectangular, length and width size is N * M. As shown in the figure:
Bob and Alice with their own definition of the coordinate system respectively, went to the coordinate point (x, y). Can they meet with each other ?
Note: Bob and Alice before reaching its destination, can not see each other because of some factZ??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcnMgKHN1Y2ggYXMgYnVpbGRpbmdzLCB0aW1lIHBvb3IpLgogCjxicj4KSW5wdXQKVGhlcmUgYXJlIG11bHRpcGxlIHRlc3QgY2FzZXMuIFBsZWFzZSBwcm9jZXNzIHRpbGwgRU9GLiBFYWNoIHRlc3QgY2FzZSBvbmx5IGNvbnRhaW5zIGZvdXIgaW50ZWdlcnMgOiBOLCBNIGFuZCB4LCB5LiBUaGUgU3F1YXJlIHNpemUgaXMgTiAqIE0sIGFuZCBtZWV0IGluIGNvb3JkaW5hdGUgcG9pbnQgKHgsIHkpLiAoIDAgPCB4IDwgTiA8PSAxMDAwICwgMCA8IHkgPCBNIDw9IDEwMDAgKS4KIAo8YnI+Ck91dHB1dApJZiB0aGV5IGNhbiBtZWV0IHdpdGggZWFjaCBvdGhlciwgcGxlYXNlIG91dHB1dCA="YES". Otherwise, please output "NO".
Sample Input
10 10 5 5
10 10 6 6
Sample Output
YES
NO
Source BestCoder Round #11 (Div. 2)
意解:水题
AC代码:
#include
#include
using namespace std; int main() { int n,m,x,y; while(cin>>n>>m>>x>>y) { if(n - x == x && m - y == y) puts("YES"); else puts("NO"); } return 0; }
Bob and math problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 375 Accepted Submission(s): 142
Problem Description Recently, Bob has been thinking about a math problem.
There are N Digits, each digit is between 0 and 9. You need to use this N Digits to constitute an Integer.
This Integer needs to satisfy the following conditions:
1. must be an odd Integer.
2. there is no leading zero.
3. find the biggest one which is satisfied 1, 2.
Example:
There are three Digits: 0, 1, 3. It can constitute six number of Integers. Only "301", "103" is legal, while "130", "310", "013", "031" is illegal. The biggest one of odd Integer is "301".
Input There are multiple test cases. Please process till EOF.
Each case starts with a line containing an integer N ( 1 <= N <= 100 ).
The second line contains N Digits which indicate the digit $a_1, a_2, a_3, \cdots, a_n. ( 0 \leq a_i \leq 9)$.
Output The output of each test case of a line. If you can constitute an Integer which is satisfied above conditions, please output the biggest one. Otherwise, output "-1" instead.
Sample Input
3
0 1 3
3
5 4 2
3
2 4 6
Sample Output
301
425
-1
意解:贪心处理,注意前导零;
AC代码:
#include
#include
#include
using namespace std; bool cmp(int a, int b) { return a > b; } int main() { int n,v,p,zoro,a[110]; while(cin>>n) { v = 10,p = zoro = 0; for(int i = 0; i < n; i++) { scanf("%d", a + i); if(a[i] % 2 && a[i] < v) v = a[i], p = 1; if(a[i] == 0) zoro++; } if(!p || zoro == n - 1 && zoro) puts("-1"); else { sort(a,a + n,cmp); for(int i = 0; i < n; i++) { if(a[i] != v) printf("%d",a[i]); else p = v,v = -1; } printf("%d\n",p); } } return 0; }
Boring count
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub |