又打了一场ABC。
结果:A,B,C题 AC(600分),D题样例就TLE,懒得提交,其它都没做。
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
目录
网址
A题
题目描述
题目分析
题目代码
B题
题目描述
题目分析
题目代码
C题
题目描述
题目分析
题目代码
其它 ? ?
我的Atcoder账号
版权声明
网址
AtCoder Beginner Contest 247 - AtCoderAtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.https://atcoder.jp/contests/abc247
A题
A - Move RightAtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.https://atcoder.jp/contests/abc247/tasks/abc247_a
题目描述
A - Move Right /
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 100 points
Problem Statement
There are 4 squares lined up horizontally.
You are given a string S of length 4 consisting of 0 and 1.
If the i-th character of S is 1, there is a person in the i-th square from the left;
if the i-th character of S is 0, there is no person in the i-th square from the left.
Now, everyone will move to the next square to the right simultaneously. By this move, the person who was originally in the rightmost square will disappear.
Determine if there will be a person in each square after the move. Print the result as a string in the same format as S. (See also Sample Input / Output for clarity.)
Constraints
S is a string of length 4 consisting of 0 and 1.
Input
Input is given from Standard Input in the following format:
S
Output
Print a string of length 4 such that the i-th character is 1 if there will be a person in the i-th square from the left after the move, and 0 otherwise.
Sample Input 1
Copy
1011
Sample Output 1
Copy
0101
After the move, the person who was originally in the 1-st square will move to the 2-nd square,
the person in the 3-rd square to the 4-th square,
and the person in the 4-th square will disappear.
Sample Input 2
Copy
0000
Sample Output 2
Copy
0000
Sample Input 3
Copy
1111
Sample Output 3
Copy
0111
题目分析
题目大意:
有4个正方形水平排列。给你一个长度为4的字符串S,由0和1组成。如果S的第i个字符是1,则在左边的第i个正方形中有一个人;如果S的第i个字符为0,则左侧的第i个正方形中没有人。现在,所有人将同时移动到右边的下一个广场。通过这个动作,原本在最右边广场上的人将消失。确定搬家后每个广场是否有人。以与S相同的格式将结果打印为字符串(为清楚起见,另请参见示例输入/输出)。
思路:很简单,直接看代码。
题目代码
AC代码(此题有点水):
#include<bits/stdc++.h>
#define ll long long
#define sz(_s) (int)_s.size()
using namespace std;
int main(){
string s="0000000000";
for(int i=1;i<5;i++) cin>>s[i];
if(s[4]) s[4]='1';
for(int i=0;i<4;i++) cout<<s[i];
return 0;
}
//ACplease!!!
/* printf(" \n");
printf(" \n");
printf(" * * * * * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * \n");
*/
B题
B - Unique NicknamesAtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.https://atcoder.jp/contests/abc247/tasks/abc247_b
题目描述
B - Unique Nicknames /
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 200 points
Problem Statement
There are N people numbered Person 1, Person 2, …, and Person N. Person i has a family name s
i
?
and a given name t
i
?
.
Consider giving a nickname to each of the N people. Person i's nickname a
i
?
should satisfy all the conditions below.
a
i
?
coincides with Person i's family name or given name. In other words, a
i
?
=s
i
?
and/or a
i
?
=t
i
?
holds.
a
i
?
does not coincide with the family name and the given name of any other person. In other words, for all integer j such that 1≤j≤N and i
=j, it holds that a
i
?
=s
j
?
and a
i
?
=t
j
?
.
Is it possible to give nicknames to all the N people? If it is possible, print Yes; otherwise, print No.
Constraints
2≤N≤100
N is an integer.
s
i
?
and t
i
?
are strings of lengths between 1 and 10 (inclusive) consisting of lowercase English alphabets.
Input
Input is given from Standard Input in the following format:
N
s
1
?
t
1
?
s
2
?
t
2
?
?
s
N
?
t
N
?
Output
If it is possible to give nicknames to all the N people, print Yes; otherwise, print No.
Sample Input 1
Copy
3
tanaka taro
tanaka jiro
suzuki hanako
Sample Output 1
Copy
Yes
The following assignment satisfies the conditions of nicknames described in the Problem Statement: a
1
?
= taro, a
2
?
= jiro, a
3
?
= hanako. (a
3
?
may be suzuki, too.)
However, note that we cannot let a
1
?
= tanaka, which violates the second condition of nicknames, since Person 2's family name s
2
?
is tanaka too.
Sample Input 2
Copy
3
aaa bbb
xxx aaa
bbb yyy
Sample Output 2
Copy
No
There is no way to give nicknames satisfying the conditions in the Problem Statement.
Sample Input 3
Copy
2
tanaka taro
tanaka taro
Sample Output 3
Copy
No
There may be a pair of people with the same family name and the same given name.
Sample Input 4
Copy
3
takahashi chokudai
aoki kensho
snu ke
Sample Output 4
Copy
Yes
We can let a
1
?
= chokudai, a
2
?
= kensho, and a
3
?
= ke.
题目分析
题目大意:有n个人,每个人有名和姓,现在给每个人取一个昵称,只能是TA自己名或姓且不能是他人的名或姓, 求是否可行。
思路:用个map统计每个字符串出现的次数,如果某人的名姓不同且名姓出现次数都大于1,则不可行。
题目代码
AC代码(此题有点水):
#include<bits/stdc++.h>
#define ll long long
#define sz(_s) (int)_s.size()
using namespace std;
int main(){
map<string,int>name;
string s[110],t[110];
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>s[i];
cin>>t[i];
name[s[i]]=0;
name[t[i]]=0;
}
for(int i=0;i<n;i++){
name[s[i]]++;
name[t[i]]++;
}
for(int i=0;i<n;i++){
if(!(name[s[i]]==1||name[t[i]]==1)){
if(s[i]!=t[i]){
cout<<"No";
return 0;
}
}
}
cout<<"Yes";
return 0;
}
//ACplease!!!
/* printf(" \n");
printf(" \n");
printf(" * * * * * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * \n");
*/
C题
C - 1 2 1 3 1 2 1AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.https://atcoder.jp/contests/abc247/tasks/abc247_c
题目描述
We define sequences S
n
?
as follows.
S
1
?
is a sequence of length 1 containing a single 1.
S
n
?
(n is an integer greater than or equal to 2) is a sequence obtained by concatenating S
n?1
?
, n, S
n?1
?
in this order.
For example, S
2
?
and S
3
?
is defined as follows.
S
2
?
is a concatenation of S
1
?
, 2, and S
1
?
, in this order, so it is 1,2,1.
S
3
?
is a concatenation of S
2
?
, 3, and S
2
?
, in this order, so it is 1,2,1,3,1,2,1.
Given N, print the entire sequence S
N
?
.
Constraints
N is an integer.
1≤N≤16
Input
Input is given from Standard Input in the following format:
N
Output
Print S
N
?
, with spaces in between.
Sample Input 1
Copy
2
Sample Output 1
Copy
1 2 1
As described in the Problem Statement, S
2
?
is 1,2,1.
Sample Input 2
Copy
1
Sample Output 2
Copy
1
Sample Input 3
Copy
4
Sample Output 3
Copy
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
S
4
?
is a concatenation of S
3
?
, 4, and S
3
?
, in this order.
题目分析
题目大意:字符串s[1]=“1”,当i>1,si=s[i-1]+i+s[i-1]。输出s[n];
思路(第一个代码):标记后不空格隔开,否则反之。
思路(第二个代码):简单循环即可,字符串不需数组。
思路(第三个代码):递归。
题目代码
第一个代码--赛时AC代码(想复杂了):
#include<bits/stdc++.h>
#define ll long long
#define sz(_s) (int)_s.size()
using namespace std;
int main(){
string s[20];
int n; cin>>n;
s[1]="1";
for(int i=1;i<=n;i++) {
if(i<10) s[i]=s[i-1]+char(i+'0')+s[i-1];
else s[i]=s[i-1]+')'+'1'+char(i%10+'0')+s[i-1];
}
for(int i=0;i<sz(s[n]);) {
if(s[n][i]==')') {
cout<<s[n][i+1];
i=i+2;
} else{
cout<<s[n][i]<<" ";
i++;
}
}
return 0;
}
//ACplease!!!
/* printf(" \n");
printf(" \n");
printf(" * * * * * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * \n");
*/
第二个代码--赛后AC代码:
#include <bits/stdc++.h>
using namespace std;
int main() {
int N; cin>>N;
string S="1";
for(int i=2;i<N+1;i++) S=S+" "+to_string(i)+" "+S;
cout<<S;
return 0;
}
第三个代码--赛后AC代码:
#include<bits/stdc++.h>
using namespace std;
string dfs(int n) {
if(n==1) return "1";
string num=to_string(n);
return dfs(n-1)+' '+num+' '+dfs(n-1);
}
int main() {
int n;
cin>>n;
string ans=dfs(n);
cout<<ans;
}
其它 ? ?
D题样例就TLE,懒得提交,其它都没做。
(排名:4925)
我的Atcoder账号
joe_zxq - AtCoderAtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.https://atcoder.jp/users/joe_zxq
版权声明
———————————————— 版权声明:本文为CSDN博主「joe_zxq21」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明, ?不欢迎 ? 欢迎大家的转载和关注。
|