快速切题 cf1A 4A 158A

1A. Theatre Square
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

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.

Input

The input contains three positive integer numbers in the first line: n,  m and a (1 ≤  n, m, a ≤ 109).

Output

Write the needed number of flagstones.

Sample test(s)
input
6 6 4
output
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 调试信息没删除

4A. Watermelon
time limit per test
1 second
memory limit per test
64 megabytes
input
standard input
output
standard output

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.

Input

The first (and the only) input line contains integer number w (1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys.

Output

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.

Sample test(s)
input
8
output
YES
Note

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).

思路:可以切分成两个偶正数,所以n>2&&n&1==0
应用时 0.5min
实际用时 8min
1 WA n==2时只能划分成1 1或0 2
2 WA 认为可以切分多块只取两块偶数
 
#include <cstdio>
int main(){
    int n;
    scanf("%d",&n);
    printf(n<=2||n&1?"NO\n":"YES\n");
    return 0;
}
158A. Next Round
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

"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.

Input

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

Output the number of participants who advance to the next round.

Sample test(s)
input
8 5
10 9 8 7 7 7 5 5
output
6
input
4 2
0 0 0 0
output
0
Note

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;
}

posted @ 2014-08-09 23:38  雪溯  阅读(156)  评论(0)    收藏  举报