又是一轮CF
A题挂了,还好unrated
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 = 30000. 30000 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.
The only line contains two integers n and k (1 ≤ n ≤ 109, 0 ≤ k ≤ 8).
Print the k-rounding of n.
375 4
30000
10000 1
10000
38101 0
38101
123456789 8
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题,给出一些房间号在第几层,房号沿着楼层上升单调增加,每层数量相等,求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;
}
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.
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
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.
hellno
hell no
abacaba
abacaba
asdfasdf
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;
}
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: 123456789, 100000000and 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.
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.
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.
3 123456789 100000000 100123456
9 000 01
4 123456789 193456789 134567819 934567891
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题,模拟题,没什么意思,跳过。。。
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.
The first line contains two integers n, m (1 ≤ n ≤ 2·105, 0 ≤ 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 ≤ n, ai ≠ 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.
In the first line print w — the maximum possible number of episodes. The next w lines should contain the episodes in format x, y, z — the three integers denoting the ids of the cities in the order of the wizard's visits.
4 5
1 2
3 2
2 4
3 4
4 1
2
1 4 2
4 3 2
5 8
5 3
1 2
4 5
5 1
2 5
4 3
1 4
3 2
4
1 4 5
2 3 4
1 5 3
5 2 1
这题挺有意思的~
详细题解 请戳这里