Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1) ABCDF

又是一轮CF

A题挂了,还好unrated


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 10 and 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

A题,10肯定只能由2*5或者1*10构成,那么对于每个因子求出可以构造多少个就可以了。


#include <cstdio>
#include <iostream>
#include <string.h>
#include <string> 
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn=100005,inf=0x3f3f3f3f;  
const ll llinf=0x3f3f3f3f3f3f3f3f;   
const ld pi=acos(-1.0L);

int main() {
	ll n,k,ans=1,j,c5,c2,cnt;
	int i;
	cin >> n >> k;
	c5=c2=cnt=0;
	ll p=n;
	while (p%10==0&&cnt+c5<k) {
		cnt++;
		p/=10;
	}
	while (p%5==0&&cnt+c5<k) {
		c5++;
		p/=5;
	}
	while (p%2==0&&cnt+c5+c2<k) {
		c2++;
		p/=2;
	}
	ans=n;
	for (i=1;i<=c5;i++) ans*=2;
	for (i=1;i<=c2;i++) ans*=5;
	for (i=cnt+c5+c2+1;i<=k;i++) ans*=10;
	cout << ans << 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 1from 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 3
6 2
2 1
7 3
output
4
input
8 4
3 1
6 2
5 2
2 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.





B题,给出一些房间号在第几层,房号沿着楼层上升单调增加,每层数量相等,求n号是否有唯一的楼层。


枚举每层的房间数量看能不能满足所有要求,可以的话算一算这时n在第几层。复杂度O(n^2)


#include <cstdio>
#include <iostream>
#include <string.h>
#include <string> 
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn=105,inf=0x3f3f3f3f;  
const ll llinf=0x3f3f3f3f3f3f3f3f;   
const ld pi=acos(-1.0L);
int a[maxn],b[maxn];
bool f[maxn];

int main() {
	int n,m,i,j,k,sum=0;
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++) {
		scanf("%d%d",&a[i],&b[i]);
	}
	mem0(f);
//	for (i=1;i<=100;i++) {
		for (j=1;j<=100;j++) {
			int flag=0;
			for (k=1;k<=m;k++) {
				if (a[k]>(b[k]-1)*j&&a[k]<=b[k]*j) continue;
				flag=1;
			}
			if (!flag) {
				f[(n-1)/j+1]=1;
			} 
		}
//	}
    int ans;
    for (i=1;i<=100;i++) if (f[i]) sum++,ans=i;
    if (sum==1) printf("%d",ans); else cout << -1;
	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 

C题,要求一个字符串没有连续三个字符都是辅音且这三个字符不等,问原串最少分成几个字符串。


贪心搞一搞,碰到不符合要求的就加一个空格。

这题花的时间比B还要少...


#include <cstdio>
#include <iostream>
#include <string.h>
#include <string> 
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn=3005,inf=0x3f3f3f3f;  
const ll llinf=0x3f3f3f3f3f3f3f3f;   
const ld pi=acos(-1.0L);
char s[maxn];

int main() {
	map<char,int> mp;
	mp['a']=mp['e']=mp['i']=mp['o']=mp['u']=1;
	int cnt=0,i,len;
	scanf("%s",s+1);
	len=strlen(s+1);
	for (i=1;i<=len;i++) {
		if (mp[s[i]]==0) cnt++; else cnt=0;
		if (cnt==3) {
			if (!(s[i]==s[i-1]&&s[i-1]==s[i-2])) {
				printf(" ");
			    cnt=1;
			} else cnt--;
		}
		printf("%c",s[i]);
	}
	return 0;
}

D. Polycarp's phone book
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct.

There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which there is a substring equal to the entered sequence of digits. For example, is there are three phone numbers in Polycarp's contacts: 123456789100000000and 100123456, then:

  • if he enters 00 two numbers will show up: 100000000 and 100123456,
  • if he enters 123 two numbers will show up 123456789 and 100123456,
  • if he enters 01 there will be only one number 100123456.

For each of the phone numbers in Polycarp's contacts, find the minimum in length sequence of digits such that if Polycarp enters this sequence, Berdroid shows this only phone number.

Input

The first line contains single integer n (1 ≤ n ≤ 70000) — the total number of phone contacts in Polycarp's contacts.

The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct.

Output

Print exactly n lines: the i-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the i-th number from the contacts. If there are several such sequences, print any of them.

Examples
input
3
123456789
100000000
100123456
output
9
000
01
input
4
123456789
193456789
134567819
934567891
output
2
193
81
91

D题,有很多个数字组成的长度为9的字符串,问对于每个串,怎么选长度最短的子串使得其他串都不含有这个子串。保证所有串不同。


用字典树搞。把所有串的所有后缀全部插入字典树,树上每个点设一个权值val,表示到达这点的所有串是由多少个不同的原串构成的。为了判断到达某点的后缀所属的原串是否已经被算在val里面,搞一个时间戳 t , 记录上一个到达该点的后缀所属的原串编号。查询时,枚举所有可能的开头字符,沿着字符串走,如果遇到val为1的位置说明查询成功,更新最短长度和开头位置。

最多70000*(1+2+3...+9)=3150000个字符,用trie还是不会爆空间的。最后搞了147MB。


#include <cstdio>
#include <iostream>
#include <string.h>
#include <string> 
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn=70005,inf=0x3f3f3f3f;  
const ll llinf=0x3f3f3f3f3f3f3f3f;   
const ld pi=acos(-1.0L);
char s[maxn][15];
int num;

struct Tree{ 
    int son[10],val,t; 
	void init() {
		for (int i=0;i<10;i++) son[i]=-1;
		val=t=0;
	}
};
Tree tree[maxn*45]; 

void insert(int now,int n,int i) {
	if (n==10) return;
	tree[now].t=i;
	if (tree[now].son[s[i][n]-'0']==-1) {
		tree[now].son[s[i][n]-'0']=num++;
		tree[num-1].init();
	}
	int p=tree[now].son[s[i][n]-'0'];
	if (tree[p].t!=i) tree[p].val++;
	insert(tree[now].son[s[i][n]-'0'],n+1,i);
}

int findx(int now,int dep,int pos,int i) {
	if (tree[now].val==1) return dep;
	if (pos==10) return inf;
	return findx(tree[now].son[s[i][pos]-'0'],dep+1,pos+1,i);
}

int main() {
	int n,i,j;
	scanf("%d",&n);
	num=1;tree[0].init();
	for (i=1;i<=n;i++) {
		scanf("%s",s[i]+1);
		tree[0].val++;
		for (j=1;j<=9;j++) {
			insert(0,j,i);
		}
	}
	for (i=1;i<=n;i++) {
		int p=0,len=inf;
		for (j=1;j<=9;j++) {
			int f=findx(0,0,j,i);
			if (f<len) {
				len=f;
				p=j;
			}
		}
		len=max(len,1);
		for (j=0;j<len;j++) printf("%c",s[i][j+p]);
		printf("\n");
	}
	return 0;
}


E题,模拟题,没什么意思,跳过。。。


F. Wizard's Tour
time limit per test
 2 seconds
memory limit per test
 256 megabytes
input
 standard input
output
 standard output

All Berland residents are waiting for an unprecedented tour of wizard in his Blue Helicopter over the cities of Berland!

It is well-known that there are n cities in Berland, some pairs of which are connected by bidirectional roads. Each pair of cities is connected by no more than one road. It is not guaranteed that the road network is connected, i.e. it is possible that you can't reach some city from some other.

The tour will contain several episodes. In each of the episodes:

  • the wizard will disembark at some city x from the Helicopter;
  • he will give a performance and show a movie for free at the city x;
  • he will drive to some neighboring city y using a road;
  • he will give a performance and show a movie for free at the city y;
  • he will drive to some neighboring to y city z;
  • he will give a performance and show a movie for free at the city z;
  • he will embark the Helicopter and fly away from the city z.

It is known that the wizard doesn't like to use roads, so he agrees to use each road at most once (regardless of direction). In other words, for road between a and b he only can drive once from a to b, or drive once from b to a, or do not use this road at all.

The wizards wants to plan as many episodes as possible without violation the above rules. Help the wizard!

Please note that the wizard can visit the same city multiple times, the restriction is on roads only.

Input

The first line contains two integers nm (1 ≤ n ≤ 2·1050 ≤ m ≤ 2·105) — the number of cities and the number of roads in Berland, respectively.

The roads description follow, one in each line. Each description is a pair of two integers ai, bi(1 ≤ ai, bi ≤ nai ≠ bi), where ai and bi are the ids of the cities connected by the i-th road. It is guaranteed that there are no two roads connecting the same pair of cities. Every road is bidirectional. The cities are numbered from 1 to n.

It is possible that the road network in Berland is not connected.

Output

In the first line print w — the maximum possible number of episodes. The next w lines should contain the episodes in format xyz — the three integers denoting the ids of the cities in the order of the wizard's visits.

Examples
input
4 5
1 2
3 2
2 4
3 4
4 1
output
2
1 4 2
4 3 2
input
5 8
5 3
1 2
4 5
5 1
2 5
4 3
1 4
3 2
output
4
1 4 5
2 3 4
1 5 3
5 2 1


这题挺有意思的~


详细题解 请戳这里

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值