Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed.
/* problem:cf-614A */ /* author: dang */ /* date: 2016-1-25 22:38 */ /* 题目大意: k的次方数只要在区间(l,r)内就输出,如果没有输出-1. */ /* ac代码 */ #include <cstdio> #include <cstring> int main(){ long long l, r, k, a = 1; int flag=0; scanf("%I64d%I64d%I64d", &l, &r, &k); while(a<=r){ if(a>=l) {printf("%I64d ", a); flag = 1;} if((r/a)<k) break; a *= k; } if(flag==0) printf("-1\n"); printf("\n"); return 0; }
<pre name="code" class="cpp">/* wa代码 不知道错哪里了。。。请指教 */ #include <cstdio> #include <cstring> int main(){ long long l, r, k, a, flag=0; scanf("%I64d%I64d%I64d", &l, &r, &k); if(l==1) { printf("1"); flag = 1; } a = k; while(k<=r){ if(k>=l) printf(" %I64d", k); if((r/k)<a) break; k *= a; flag = 1; } if(flag==0) printf("-1\n"); printf("\n"); return 0; }
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse!
There are exactly n distinct countries in the world and thei-th country added ai tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. Abeautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks ofone country was removed from the game, hence the number of tanks of this country may not remain beautiful.
Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.
The first line of the input contains the number of countries n (1 ≤ n ≤ 100 000). The second line containsn non-negative integers ai without leading zeroes — the number of tanks of thei-th country.
It is guaranteed that the second line contains at least n - 1 beautiful numbers and the total length of all these number's representations doesn't exceed100 000.
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
3 5 10 1
50
4 1 1 10 11
110
5 0 3 1 100 1
0
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2 number 11 is not beautiful (contains two '1's), all others arebeautiful.
In sample 3 number 3 is not beautiful, all others arebeautiful.
<pre name="code" class="cpp">/* problem:cf-614B */ /* author: dang */ /* date: 2016-1-26 10:18 */ /* 题目大意: 有0就输出0,否则有unbeautiful数时,把这个数放在最开始,然后记录beautiful数一共有多 少0,就输出几个0,若全为beautiful数,就输出1,然后把beautiful数中的0全部输出。 */ #include<iostream> #include<string> using namespace std; int main(){ int n, flag = 0, num_0=0, flag_u , cnt; string str, ans="1"; //初始化ans为1,考虑全部都为beautiful数时的情况 cin>>n; for(int i = 0; i < n; i++){ cin>>str; if(str[0] == '0') { //判断是否是0 flag = 1; continue; } cnt = flag_u = 0; for(unsigned int j = 0; j <str.length(); j ++){ if(str[j]=='0') cnt++; //计算0的个数 else if(str[j]!='0'&&str[j]!='1') flag_u = 1; //判断是否有除0和1以外的数 } if(flag_u||(str.length()-cnt!=1)) { //判断是否是beautiful数 ans = str; } else num_0 += cnt; //若不是记录0的个数 } if(flag) cout<<"0"<<endl; //有0直接输出0 else { cout<<ans; for(int i = 0; i < num_0; i++) cout<<"0"; cout<<endl; } return 0; }