codeforces_easy_1to5
来源:互联网 发布:红米清空数据失败 编辑:程序博客网 时间:2024/06/17 03:02
include<iostream>
int main()
{cout<<"Hello World!David.";}
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
Tips:因为题目说可以large than Square,所以不能整除时就可以m/a+1,然后分类讨
论即可。
answers:
#include<iostream>using namespace std;int main(){long long m;long long n;long long a;cin>>m>>n>>a;long long x=0;long long y=0;if(m>a&&m%a!=0){ x=(m/a)+1;}else if(m%a==0){ x=m/a;}else if(m<=a){ x=1;}if(n>a&&n%a!=0){ y=(n/a)+1;}else if(n%a==0){ y=n/a;}else if(n<=a){ y=1;}cout<<x*y;return 0;}
4A. Watermelontime limit per test1 secondmemory limit per test64 megabytesinputstandard inputoutputstandard outputOne 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.
InputThe first (and the only) input line contains integer number w (1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys.
OutputPrint 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.
Examplesinput8outputYESTips:因为题目说只要能分成两个偶数,所以只要是偶数就一定能分,而且大于零即可,两个小孩分西瓜,数据能出到100kg,真怀疑他们咋吃得完。
answers:
#include<iostream>using namespace std;int main(){ int num=0; cin>>num; if(num%2==0&&num>2) cout<<"YES"; else cout<<"NO";}71A. Way Too Long Wordstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
InputThe first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
OutputPrint n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
Examplesinput4wordlocalizationinternationalizationpneumonoultramicroscopicsilicovolcanoconiosisoutputwordl10ni18np43sTips:因为题目说字符串太长了,保留一头一尾,中间省略,所以就可以直接引入
<cstring>头文件。
调用string.size()这个函数用来显示一头一尾的字符和string.si
ze()-2即可。
answers:
#include<iostream>#include<cstring>using namespace std;int main(){ string a; int number=0; cin>>number; while(number>0) { cin>>a; if(a.size()<=10) { cout<<a; } else { cout<<a[0]<<a.size()-2<<a[a.size()-1]; } cout<<endl; number--; }}158A. Next Roundtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard 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.
InputThe 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).
OutputOutput the number of participants who advance to the next round.
Examplesinput8 510 9 8 7 7 7 5 5output6input4 20 0 0 0output0Tips:只要大等于第几位就可以了,注意字符串是从0开始存的,所以比较的是k-1。
当然还要大于零,实例里讲了。
answers:
#include<iostream>using namespace std;int main(){ int n,k; cin>>n>>k; int a[51]={0}; int i=0; while(i<n) { cin>>a[i]; i++; } int ji=0; for(int m=0;m<n;m++) { if(a[m]>=a[k-1]&&a[m]>0) ji++; } cout<<ji;}118A. String Tasktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels,
- inserts a character "." before each consonant,
- replaces all uppercase consonants with corresponding lowercase ones.
Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.
Help Petya cope with this easy task.
InputThe first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
OutputPrint the resulting string. It is guaranteed that this string is not empty.
Examplesinputtouroutput.t.rinputCodeforcesoutput.c.d.f.r.c.sinputaBAcAbaoutput.b.c.bTips:先把小写转成大写是一定的,用ASCII码,然后比较简单的输出方式就是判断
不是元音字符就先输出“.”。然后输出该字符,当然先剔除这些元音在输出也可以,对
于这题稍麻烦些。
answers:
#include <iostream>#include <cstring>using namespace std;int main(){ int i, l; string str; cin >> str; l = str.length(); for (i = 0; i <= l - 1; i++) { if (str[i] < 97) str[i] = str[i] + 32; if (str[i] != 97 && str[i] != 101 && str[i] != 105 && str[i] != 111 && str[i] != 117 && str[i] != 121) cout << '.' << str[i]; } cout << endl; return 0;}今天题目介绍到这里,第一次没什么经验。欢迎各路大神不吝赐教,随时指正。
以后整理些稍复杂的acm题和一些算法,Fighting!