A - Karen and Morning
Karen is getting ready for a new school day!
It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.
What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?
Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.
InputThe first and only line of input contains a single string in the format hh:mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59).
Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.
05:39
11
13:31
0
23:59
1
In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.
In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.
In the third test case, the minimum number of minutes Karen should sleep for is 1minute. She can wake up at 00:00, when the time is a palindrome
简单的回文串模拟
#include<stdio.h>
int main(void) {
int min;
int hour;
int i;
int x_1;
int x_2;
int y_1;
int y_2;
scanf("%d:%d",&hour,&min);
for(i = 0; ;i++) {
x_1 = hour / 10;
x_2 = hour % 10;
y_1 = min / 10;
y_2 = min % 10;
if(x_1 == y_2 && x_2 == y_1) {
printf("%d\n",i);
break;
}
if(min == 59 && hour == 23) {
printf("%d\n",i+1);
break;
}
min++;
if(min > 59) {
min = 0;
hour++;
}
}
return 0;
}
C - Sagheer and Crossroads
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (l — left, s — straight, r — right) and a light p for a pedestrian crossing.
An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.
Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible.
InputThe input consists of four lines with each line describing a road part given in a counter-clockwise order.
Each line contains four integers l, s, r, p — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.
On a single line, print "YES" if an accident is possible, and "NO" otherwise.
1 0 0 1 0 1 0 0 0 0 1 0 0 0 0 1
YES
0 1 1 0 1 0 1 0 1 1 0 0 0 0 0 1
NO
1 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0
NO
In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.
In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur.
模拟交通状况,暴力
#include<stdio.h>
int main(void) {
int i;
int l[5],s[5],r[5],p[5];
for(i = 0;i < 4;i++) {
scanf("%d %d %d %d",&l[i],&s[i],&r[i],&p[i]);
}
for(i = 0;i < 4;i++) {
if(p[i] == 0) {
continue;
}
if(l[i] || s[i] || r[i]) {
break;
}
if(l[(i+1)%4] || s[(i+2)%4] || r[(i+3)%4]) {
break;
}
}
if(i == 4) {
puts("NO");
} else {
puts("YES");
}
return 0;
}
E - Straight «A»
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8.
For instance, if Noora has marks [8, 9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8, 8, 9], Noora will have graduation certificate with 8.
To graduate with «A» certificate, Noora has to have mark k.
Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to k.
InputThe first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ k) denoting marks received by Noora before Leha's hack.
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.
2 10 8 9
4
3 5 4 4 4
3
Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to . Consequently, new final mark is 10. Less number of marks won't fix the situation.
In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.
m个所给数据和i个k的平均值四舍五入之后还是k
#include<stdio.h>
int main(void) {
int n;
int m;
int i;
int a;
double ave = -1;
double target_1;
double target_2;
double sum = 0.0;
scanf("%d %d",&m,&n);
target_1 = n - 0.5;
target_2 = n + 0.5;
for(i = 0;i < m;i++) {
scanf("%d",&a);
sum += a;
}
for(i = 1;ave < target_1 || ave >= target_2;i++) {
sum += n;
ave = sum / (m+i);
}
printf("%d\n",i - 1);
return 0;
}