比赛链接:
A. Drazil and Date
time limit per test 1 second
memory limit per test 256 megabytes
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil’s home is located in point(0,0) and Varda’s home is located in point(a,b). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position(x,y) he can go to positions(x+1,y),(x-1,y),(x,y+1) or(x,y-1).
Unfortunately, Drazil doesn’t have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (a,b) and continue travelling.
Luckily, Drazil arrived to the position (a,b) successfully. Drazil said to Varda: "It took me exactlys steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from(0,0) to (a,b) in exactlys steps. Can you find out if it is possible for Varda?
Input
You are given three integers a, b, and s (-109≤a,b≤109,1≤s≤2·109) in a single line.
Output
If you think Drazil made a mistake and it is impossible to take exactlys steps and get from his home to Varda’s home, print "No" (without quotes).
Otherwise, print "Yes".
Sample test(s)
Input
5 5 11
Output
No
Input
10 15 25
Output
Yes
Input
0 5 1
Output
No
Input
0 0 2
Output
Yes
Note
In fourth sample case one possible route is: .
题目大意:判断从原点(0,0)走整整s步有没有可能到点(a,b)
题目分析:坐标可能是负的,先把曼哈顿距离算出来,a + b > s不可能,, a + b – s是2的倍数可能,否则不可能
#include <cstdio>int main(){int a, b, s;scanf("%d %d %d", &a, &b, &s);if(a < 0)a = -a;if(b < 0)b = -b;if(a + b > s){printf("No\n");return 0;}if(a + b <= s && (a + b – s) % 2 == 0)printf("Yes\n");elseprintf("No\n");}
B. Drazil and His Happy Friends
time limit per test 2 seconds
memory limit per test 256 megabytes
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys andm girls among his friends. Let’s number them from0 ton-1 and0 tom-1 separately. Ini-th day, Drazil invites-th boy and-th girl to have dinner together (as Drazil is programmer,i starts from0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input
The first line contains two integer n and m (1≤n,m≤100).
The second line contains integer b (0≤b≤n), denoting the number of happy boys among friends of Drazil, and then followb distinct integersx1,x2,…,xb (0≤xi<n), denoting the list of indices of happy boys.
The third line conatins integer g (0≤g≤m), denoting the number of happy girls among friends of Drazil, and then followg distinct integersy1,y2,… ,yg (0≤yj<m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Sample test(s)
Input
2 301 0
Output
Yes
Input
2 41 01 2
Output
No
Input
2 31 01 1
Output
Yes
Note
同时也用对她的怀念来惩罚自己。