快速切题 cf1A 4A 158A
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.
The input contains three positive integer numbers in the first line: n, m and a (1 ≤ n, m, a ≤ 109).
Write the needed number of flagstones.
6 6 4
4
思路 (n+a-1)/a*(m-a-1)/a
应用时 1min
实际用时 30min
1 WA 没有取整而是直接+1,导致恰整除时不行
2 WA int类型无法存储10e9的平方
3 WA long long 运算中间过程爆int
4 WA 调试信息没删除
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
The first (and the only) input line contains integer number w (1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
8
YES
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
#include <cstdio>
int main(){
int n;
scanf("%d",&n);
printf(n<=2||n&1?"NO\n":"YES\n");
return 0;
}
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many participants will advance to the next round.
The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 50) separated by a single space.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the score earned by the participant who got the i-th place. The given sequence is non-increasing (that is, for all i from 1 to n - 1 the following condition is fulfilled: ai ≥ ai + 1).
Output the number of participants who advance to the next round.
8 5
10 9 8 7 7 7 5 5
6
4 2
0 0 0 0
0
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score.
思路:桶装,输出到大于等于k时的和,注意0此时可以有输出小于k
应用时 2min
实际用时 5min
1 CE 打错字母
#include <cstdio>
int num[101];
int main(){
int n,k,temp,sum=0;
scanf("%d%d",&n,&k);
while(n--){
scanf("%d",&temp);
num[temp]++;
}
for(int i=100;i>0&&sum<k;i--){
sum+=num[i];
}
printf("%d\n",aum);
return 0;
}

浙公网安备 33010602011771号