目录
刷题记录(Codeforces Round 944 (Div. 4)前四题)
刷题记录(Codeforces Round 944 (Div. 4)前四题)
1.A. My First Sorting Problem
输入样例:
10
1 9
8 4
1 4
3 4
2 0
2 4
6 9
3 3
0 0
9 9
1 9
8 4
1 4
3 4
2 0
2 4
6 9
3 3
0 0
9 9
输出样例:
1 9
4 8
1 4
3 4
0 2
2 4
6 9
3 3
0 0
9 9
4 8
1 4
3 4
0 2
2 4
6 9
3 3
0 0
9 9
签到题直接贴代码:
#include<iostream>
using namespace std;
void solve()
{
int a,b;
cin>>a>>b;
if(a<b) cout<<a<<" "<<b<<"\n";
else cout<<b<<" "<<a<<"\n";
}
int main()
{
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
2.B. Different String
输入样例:
8
codeforces
aaaaa
xxxxy
co
d
nutdealer
mwistht
hhhhhhhhhh
codeforces
aaaaa
xxxxy
co
d
nutdealer
mwistht
hhhhhhhhhh
输出样例:
YES
forcodesec
NO
YES
xxyxx
YES
oc
NO
YES
undertale
YES
thtsiwm
NO
forcodesec
NO
YES
xxyxx
YES
oc
NO
YES
undertale
YES
thtsiwm
NO
题目需要我们重新排序字符串的元素,得到一个不同的字符串,当输出NO时,只有可能是字符串都是同一个元素。
下面是AC代码:
#include<iostream>
using namespace std;
void solve()
{
string s;
cin>>s;
int f=0;
for(int i=0;i<s.size()-1;i++){
if(s[i]!=s[i+1]) f=1;
}
if(f==0||s.size()==1)
{
cout<<"NO\n";
return;
}
string t=s;int i=0,j=1;
while(t==s){//粗暴打乱,打不乱不停循环
swap(t[i],t[j]);
if(j<s.size()) j++;
else if(j==s.size()&&i<s.size()) i++;
}
cout<<"YES\n";
cout<<t<<"\n";
}
int main()
{
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
3.C. Clock and Strings
输出样例:
15
2 9 10 6
3 8 9 1
1 2 3 4
5 3 4 12
1 8 2 10
3 12 11 8
9 10 12 1
12 1 10 2
3 12 6 9
1 9 8 4
6 7 9 12
7 12 9 6
10 12 11 1
3 9 6 12
1 4 3 5
2 9 10 6
3 8 9 1
1 2 3 4
5 3 4 12
1 8 2 10
3 12 11 8
9 10 12 1
12 1 10 2
3 12 6 9
1 9 8 4
6 7 9 12
7 12 9 6
10 12 11 1
3 9 6 12
1 4 3 5
输出样例:
YES
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
题目要求我们两条线是否相交,相交则输出YES,比赛时完全是模拟一下,大概相交会有以下情况:
另外一条线的两点其中一个出现在另一条线的两点围成的劣弧里面。
![](https://img-blog.csdnimg.cn/direct/bfe1b6dbc42e4579bc841e08073006b9.png)
![](https://img-blog.csdnimg.cn/direct/05be6f7af8784d5d85a6cc20fcfefa96.png)
两点都在或者都不在则不会相交。
下面是AC代码:
#include<iostream>
using namespace std;
void solve()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
if(a>b) swap(a,b);
int cnt=0;
int ans=b-a-1;
int f=0;
if(ans>=6) cnt=11-ans,f=1;
else cnt=ans;
int p;
if(f==0) p=a;
else p=b;
int y1=0,y2=0;
for(int i=p+1;i<=p+cnt;i++){
int k=i%12;
if(k==0) k=12;
if(k==c) y1=1;
if(k==d) y2=1;
}
if((y1==1&&y2==0)||(y2==1&&y1==0))
{
cout<<"YES\n";
return;
}
cout<<"NO\n";
}
int main()
{
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
4.D. Binary Cut
输出样例:
6
11010
00000000
1
10
0001111
0110
11010
00000000
1
10
0001111
0110
输出样例:
3
1
1
2
1
2
1
1
2
1
2
有点思路,当时没想出来,还认真的去找01串,10串的个数和最长01串的长度,结果只需要找到01和10串的个数即可。
下面是AC代码:
#include<iostream>
#include<string>
using namespace std;
void solve()
{
string s;
cin>>s;
int cnt=0;
for(int i=1;i<s.size();i++){
if(s[i]!=s[i-1]) cnt++;
}
if(cnt==0)
{
cout<<"1\n";
return;
}
if(s[0]=='0') cout<<max(cnt,1)<<"\n";
else cout<<max(cnt,2)<<"\n";
}
int main()
{
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}