目标完成、、
A. Drazil and Date
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 exactly
s 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 exactly
s steps. Can you find out if it is possible for Varda?
You are given three integers a,
b, and s ( - 109 ≤ a, b ≤ 109,
1 ≤ s ≤ 2·109) in a single line.
If you think Drazil made a mistake and it is impossible to take exactly
s steps and get from his home to Varda's home, print "No" (without quotes).
Otherwise, print "Yes".
5 5 11
No
10 15 25
Yes
0 5 1
No
0 0 2
Yes
In fourth sample case one possible route is: .
问从(0,0)到(n,m)走s 步是否能恰好到达,显然要大于等于n + m步,当大于的时候,多出来的一定要能被2 整除,这样可以在反悔中消耗多出来的s 。
要注意正负号的问题、、
#include <stdio.h> #include <algorithm> #include <string.h> #include <math.h> using namespace std; int main() { int n, m, s; while(~scanf("%d%d%d",&n,&m,&s)) { n = abs(n); m = abs(m); if(n + m == s || ((n + m - s)%2 == 0 && (n + m) < s)) printf("Yes\n"); else printf("No\n"); } }
B. Drazil and His Happy Friends
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 and
m girls among his friends. Let's number them from
0 to n - 1 and
0 to m - 1 separately. In
i-th day, Drazil invites -th boy and
-th girl to have dinner together (as Drazil is programmer,
i starts from 0). 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.
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 follow
b distinct integers
x1, 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 follow
g distinct integers
y1, 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.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
2 3 0 1 0
Yes
2 4 1 0 1 2
No
2 3 1 0 1 1
Yes
By we define the remainder of integer division of
i by k.
In first sample case:
- On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
- On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
- On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
- On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
- On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
纯暴力,一直循环即可。
我在这里是循环(n + 1) * (m + 1) 遍,只是因为试了一试,( n + 1)*(m) 和 (n)*(m + 1)都没过、
这里有两组数据
3 20 0 1 19 Yes 41 2 1 33 0 Yes
#include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <math.h> #include <queue> #include <vector> #include <map> using namespace std; #define N 110 int boy[N]; int girl[N]; int main() { int n, m; int a, b; int tmp_1; while(~scanf("%d%d",&n,&m)) { memset(boy, 0, sizeof(boy)); memset(girl, 0, sizeof(girl)); scanf("%d",&a); for(int i = 0; i < a; i ++) { scanf("%d",&tmp_1); boy[tmp_1] = 1; } scanf("%d",&b); for(int i = 0; i < b; i ++) { scanf("%d",&tmp_1); girl[tmp_1] = 1; } int cnt = 0, cnt_i = 0, cnt_j = 0; int endn = (n + 1) * (m + 1); // 暴力次数 while(cnt < endn) { if(boy[cnt_i] || girl[cnt_j]) { boy[cnt_i] = 1; girl[cnt_j] = 1; } cnt_i = (cnt_i + 1)%n; cnt_j = (cnt_j + 1)%m; cnt ++; } bool ok1 = true; bool ok2 = true; for(int i = 0; i < n; i ++) { if(boy[i] == 0) { ok1 = false; break; } } for(int i = 0; i < m; i ++) { if(girl[i] == 0) { ok2 = false; break; } } if(ok1 && ok2) printf("Yes\n"); else printf("No\n"); } }
C. Drazil and Factorial
Drazil is playing a math game with Varda.
Let's define for positive integer
x as a product of factorials of its digits. For example,
.
First, they choose a decimal number a consisting of
n digits that contains at least one digit larger than
1. This number may possibly start with leading zeroes. Then they should find maximum positive number
x satisfying following two conditions:
1. x doesn't contain neither digit
0 nor digit 1.
2. =
.
Help friends find such number.
The first line contains an integer n (1 ≤ n ≤ 15) — the number of digits in
a.
The second line contains n digits of
a. There is at least one digit in a that is larger than
1. Number a may possibly contain leading zeroes.
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
4 1234
33222
3 555
555
In the first case,
题意很简单,就是使得 =
. ,x 为题目的数据,a 为输出的答案,越大越好。把数拆掉,使得位数越多越好,然后把大的数放在前位就可以了。
#include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <math.h> using namespace std; int num[15]; char s[20]; int main() { int n; while(~scanf("%d",&n)) { scanf("%s",s); int len = strlen(s); memset(num, 0, sizeof(num)); for(int i = 0; i < len; i ++) { if(s[i] == '0' || s[i] == '1') continue; if(s[i] == '4') { num[3] ++; num[2] += 2; } else if(s[i] == '6') { num[5] ++; num[3] ++; } else if(s[i] == '8') { num[7] ++; num[2] += 3; } else if(s[i] == '9') { num[3] += 2; num[2] ++; num[7] ++; } else { num[s[i] - '0'] ++; //不能拆分的,直接对该数进行计数 } } for(int i = 9; i >= 1; i --) { for(int j = 0; j < num[i]; j ++) { printf("%d",i); } } printf("\n"); } }
最后,大年三十,新~~~~~~~~~ 年 ~~~~~~~~~~~~· 快 ~~~~~~~~~~~~~ 乐 ·~~~~~~~