# CF#847 (Div. 3)ABCDE题解
Codeforces Round #847 (DFiv. 3)
A Polycarp and the Day of Pi
题目描述
On March 14, the day of the number
Polycarp was told at school that the number
Polycarp wrote out all the digits that he managed to remember. For example, if Polycarp remembered
Polycarp was in a hurry and could have made a mistake, so you decided to check how many first digits of the number
输入格式
The first line of the input data contains the single integer
Each test case is described by a single string of digits
The string
输出格式
Output
in
9
000
3
4141592653
141592653589793238462643383279
31420
31415
314159265358
27182
314159265358979323846264338327
out
0
1
0
0
3
5
12
0
30
思路
我们先保存好
看数据范围不会超时
key code
string ans="314159265358979323846264338327";
void solve(){
//try it again.
int cnt=0;
string s;
cin>>s;
n=s.size()-1;
up(0,n){
if(s[o]!=ans[o])break;
else cnt++;
}
cout<<cnt<<endl;
}
B Taisia and Dice
题目描述
Taisia has
Taisia rolls all
Suddenly, Taisia's pet cat steals exactly one dice with maximum value
You only know the number of dice
输入格式
The first line contains the integer
Each testcase is given on a separate line and contains three integers
It is guaranteed that a solution exists.
输出格式
For each testcase, print:
If there are multiple solutions, print any.
in
7
2 2 1
2 4 2
4 9 5
5 17 11
3 15 10
4 4 3
5 20 15
out
1 1
2 2
1 2 2 4
6 4 2 3 2
5 5 5
1 1 1 1
1 4 5 5 5
思路:
就是小猫偷走了一个骰子,这一个骰子是确定的点数,而且剩下的骰子里面都不能比这一个的点数大。
于是就转换成了有
根据题意可以知道一定是可以分完的,也就是说一定有可行的解
我们再依次从大到小进行选择
如果选择了这一个点数那么剩下的全都是1的点数仍然比
key code
void solve(){
//try it again.
int n,s,r;
cin>>n>>s>>r;
int tt=s-r;//偷的一个
int n0=n-1;
//分n0个骰子为r
// debug(n0);
// debug(r);
cout<<tt<<" ";
dn(tt,1){
while((o+n0-1)<=r&&n0>0){
n0--;
r-=o;
cout<<o<<" ";
}
}
cout<<endl;
}
C Premutation
题目描述
A sequence of
Kristina had a permutation
- while writing the permutation at the
-th ( time she skipped the element
So, she wrote in total
- Wrote the sequence
, skipping the element from the original permutation. - Wrote the sequence
, skipping the element from the original permutation. - Wrote the sequence
, skipping the element from the original permutation. - Wrote the sequence
, skipping the element from the original permutation.
You know all
For example, if you know the sequences
输入格式
The first line of input data contains a single integer
The description of the test cases follows.
The first line of each test case contains one integer
This is followed by
It is guaranteed that all sequences could be obtained from some permutation
输出格式
For each test case, output on a separate line a permutation
It is guaranteed that the answer exists and it is the only one. In other words, for each test case the required permutation is sure to exist.
in
5
4
4 2 1
4 2 3
2 1 3
4 1 3
3
2 3
1 3
1 2
5
4 2 1 3
2 1 3 5
4 2 3 5
4 1 3 5
4 2 1 5
4
2 3 4
1 3 4
1 2 3
1 2 4
3
2 1
1 3
2 3
out
4 2 1 3
1 2 3
4 2 1 3 5
1 2 3 4
2 1 3
提示
The first test case is described in the problem statement.
In the second test case, the sequences are written in the correct order.
思路:
显然我们可以知道在原排列中靠前的比靠后的下标要小
同理那么在子排列中原来靠前的也比原来靠后的下标要小
进而可得原来靠前的也比原来靠后的下标之和要小
那么我们就可以根据下标的和来进行排序
key code
PII cnt[110];
bool cmp(PII a,PII b){
return a.se<b.se;
}
void solve(){
//try it again.
// map<int,int>mp;
mem0(cnt);
cin>>n;
up(1,n){
cnt[o].fi=o;
}
up(1,n){
fup(i,1,n-1){
int x;
cin>>x;
cnt[x].se+=i;
}
}
sort(cnt+1,cnt+1+n,cmp);
up(1,n){
if(cnt[o].se)cout<<cnt[o].fi<<" ";
}
cout<<endl;
}
D Matryoshkas
题目描述
Matryoshka is a wooden toy in the form of a painted doll, inside which you can put a similar doll of a smaller size.
A set of nesting dolls contains one or more nesting dolls, their sizes are consecutive positive integers. Thus, a set of nesting dolls is described by two numbers:
You had one or more sets of nesting dolls. Recently, you found that someone mixed all your sets in one and recorded a sequence of doll sizes — integers
You do not remember how many sets you had, so you want to find the minimum number of sets that you could initially have.
For example, if a given sequence is
- the first set consisting of
nesting dolls with sizes ; - a second set consisting of
nesting dolls with sizes .
According to a given sequence of sizes of nesting dolls
Each set is completely used, so all its nesting dolls are used. Each element of a given sequence must correspond to exactly one doll from some set.
输入格式
The first line of input data contains a single integer
The description of the test cases follows.
The first line of each test case contains one integer
The second line of each test case contains
It is guaranteed that the sum of values of
输出格式
For each test case, print one integer
in
10
6
2 2 3 4 3 1
5
11 8 7 10 9
6
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
8
1 1 4 4 2 3 2 3
6
1 2 3 2 3 4
7
10 11 11 12 12 13 13
7
8 8 9 9 10 10 11
8
4 14 5 15 6 16 7 17
8
5 15 6 14 8 12 9 11
5
4 2 2 3 4
out
2
1
6
2
2
2
2
2
4
3
提示
The first test case is described in the problem statement.
In the second test case, all matryoshkas could be part of the same set with minimum size
In the third test case, each matryoshka represents a separate set.
思路:
这个题就是看值的变化规律
先给原数组排序并计次数
然后去掉重复的项
如果相邻两项之间的差值大于1,那么就会组成一个新的套娃
如果相邻两项之间的差值等于1,而且后面的次数大于前面的次数,那么就要把多出来的次数也加上
key code
int a[N];
bool st[N];
void solve(){
//try it again.
cin>>n;
up(1,n){
cin>>a[o];
}
map<int,int>mp;
map<int,bool>st;
sort(a+1,a+1+n);
int cnt=0;
// up(1,n)cout<<a[o]<<" \n"[o==n];
up(1,n){
mp[a[o]]++;
}
up(1,n){
if(a[o]>a[o-1]+1){
cnt+=mp[a[o]];
}
else if(a[o]==a[o-1]+1){
cnt+=(mp[a[o]]>mp[a[o-1]]?mp[a[o]]-mp[a[o-1]]:0);
}
}
cout<<cnt<<endl;
}
E Vlad and a Pair of Numbers
题目描述
Vlad found two positive numbers
Since it is easier to remember one number than two, Vlad remembered only
输入格式
The first line of the input data contains the single integer
Each test case is described by a single integer
输出格式
Output
in
6
2
5
10
6
18
36
out
3 1
-1
13 7
-1
25 11
50 22
思路:
好吧其实这个题我不会哈哈哈
我是硬打表做的
fup(i,1,100){
fup(j,i+1,100){
int x=i+j>>1;
if(((i^j)<<1)==(i+j)){
debug(((i)&x));
debug(((i&j)&x));
debug3(i,j,x);
}
}
}
((i)&x)=0
((i&j)&x)=0
i=1 j=3 x=2
((i)&x)=0
((i&j)&x)=0
i=2 j=6 x=4
((i)&x)=0
((i&j)&x)=0
i=4 j=12 x=8
((i)&x)=0
((i&j)&x)=0
i=5 j=15 x=10
((i)&x)=2
((i&j)&x)=0
i=7 j=13 x=10
((i)&x)=0
((i&j)&x)=0
i=8 j=24 x=16
((i)&x)=0
((i&j)&x)=0
i=9 j=27 x=18
((i)&x)=0
((i&j)&x)=0
通过打表我们可以发现如果存在解那么一定存在
那我们就写出来打表的代码
key code
void solve(){
//try it again.
cin>>n;
if(n&1)cout<<-1<<endl;
else{
int x=n;
if(((x>>1)&x)==0)cout<<(x>>1)<<" "<<(x*2-((x>>1)))<<endl;
else cout<<-1<<endl;
}
}
然后就过了hhh,好神奇
本文作者:liangqianxing
本文链接:https://www.cnblogs.com/liangqianxing/p/17069614.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步