Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) A-C题解

来源:互联网 发布:柏原崇 知乎 编辑:程序博客网 时间:2024/05/22 14:20

传送门:点击打开链接

A. k-rounding
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10and is divisible by n.

For example, 4-rounding of 375 is 375·80 = 3000030000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.

Write a program that will perform the k-rounding of n.

Input

The only line contains two integers n and k (1 ≤ n ≤ 1090 ≤ k ≤ 8).

Output

Print the k-rounding of n.

Examples
input
375 4
output
30000
input
10000 1
output
10000
input
38101 0
output
38101
input
123456789 8
output
12345678900000000

找到前一个数的倍数,满足后缀有K个0,输出最小的那个数。刚开始是暴力,一一枚举n的倍数,后来发现第四组示例跑死了啊,4秒才出结果,12345678900000000实在是太大了,只好换别的方法,又想到单独处理质数,然后合数求GCD试试,后来发现为什么要单独判断质数呢?直接全部GCD就OK了。


代码实现:

#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<cstdio>#define ll long long#define mset(a,x) memset(a,x,sizeof(a))using namespace std;const double PI=acos(-1);const int inf=0x3f3f3f3f;const double esp=1e-6;const int maxn=100005;const int mod=1e9+7;int dir[4][2]={0,1,1,0,0,-1,-1,0};ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}int main(){ll n,k,i,flag;while(cin>>n>>k){ll temp=fpow(10ll,k);ll ans=gcd(n,temp);cout<<temp/ans*n<<endl;}return 0;}


B. Which floor?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.

Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.

Given this information, is it possible to restore the exact floor for flat n?

Input

The first line contains two integers n and m (1 ≤ n ≤ 1000 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.

m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 1001 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.

It is guaranteed that the given information is not self-contradictory.

Output

Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.

Examples
input
10 36 22 17 3
output
4
input
8 43 16 25 22 1
output
-1
Note

In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.

In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.


这个题目的英语不是最坑的,还有c题在等着。特意找了一下别人的博客,这位同学的翻译就比较好。点击打开链接

有一幢大楼,大楼每层有相同数量的房间,假设大楼为无数层,房间号从下至上逐个增加,第一个房间的号码为1,已知m个房间所在层数,求房间号为 n 的房间所在层数。若不能确定房间所在层数,则输出”-1”

已知条件:

1.每层楼有一个或多个房间

2.每层楼的房间数量相同

3.房间号为1的房间只能在1

4.房间号从小到大递增

题解:

将所有已知的条件放入,暴力枚举一下每层房间数(1-100),找出可行的每层房间数,再算出房间n所在层数,看是否第n个房间总是在同一层。


他是暴力解决,我也是暴力,AC是同样的,暴力各有各的不同。我是找的可能出现的最小楼层跟可能出现的最大楼层,当两者相等时,此时就确定了楼层的位置,当两者不等时说明不确定位置。

代码实现:
#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<cstdio>#define ll long long#define mset(a,x) memset(a,x,sizeof(a))using namespace std;const double PI=acos(-1);const int inf=0x3f3f3f3f;const double esp=1e-6;const ll maxn=1e18;const int mod=1e9+7;int dir[4][2]={0,1,1,0,0,-1,-1,0};ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}int main(){ll l,r,n,m,i,j,k,x,y;while(cin>>n>>m){l=-maxn;r=maxn;for(i=0;i<m;i++){cin>>x>>y;l=max(l,(x+y-1)/y);if(y>1)r=min(r,(x-1)/(y-1));}if((n+l-1)/l==(n+r-1)/r)cout<<(n+l-1)/l<<endl;elsecout<<"-1"<<endl;}return 0;}

C. Did you mean...
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.

Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.

For example:

  • the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
  • the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".

When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.

Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.

Input

The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.

Output

Print the given word without any changes if there are no typos.

If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.

Examples
input
hellno
output
hell no 
input
abacaba
output
abacaba 
input
asdfasdf
output
asd fasd f 

输给了俄式英语,题意还不是特别懂,代码也是参考排名靠前大神的,而且,这题又是特判,什么鬼?又是特判,为什么总是特判。本来就不懂题意,输出还故意是那种不容易理解的示例,反正就是输出合法字符。

代码实现:
#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<cstdio>#define ll long long#define mset(a,x) memset(a,x,sizeof(a))using namespace std;const double PI=acos(-1);const int inf=0x3f3f3f3f;const double esp=1e-6;const int maxn=3e+5;const int mod=1e9+7;int dir[4][2]={0,1,1,0,0,-1,-1,0};ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}char map[maxn];int ans[maxn];int judge(char x){return x=='a'||x=='e'||x=='i'||x=='o'||x=='u';}void output(int x){if(ans[x]){output(ans[x]);cout<<' ';}for(int i=ans[x]+1;i<=x;i++){cout<<map[i];}}int main(){int i,j,k,n;while(~scanf("%s",map+1)){getchar();n=strlen(map+1);int x,y,z;for(i=1;i<=n;i++){x=i;y=!judge(map[i]);z=0;while(y<=2||z==0){x--;if(!x)break;if(judge(map[x])){y=0;z=0;}else{if(y&&map[x]!=map[x+1])z=1;y++;}}ans[i]=x;}output(n);cout<<endl;}return 0;}
阅读全文
0 0
原创粉丝点击