比赛复盘
Cookie_King · · 个人记录
A 杀手游戏
Problem
描述
有
输入描述
第一行包含一个整数
第二行包含
输出描述
打印一个整数,表示没中枪的人数总数。
用例输入 1
4
0 1 0 10
用例输出 1
1
用例输入 2
2
0 0
用例输出 2
2
用例输入 3
10
1 1 3 0 0 0 2 1 0 3
用例输出 3
3
提示
子任务一:
子任务二:
子任务三:
Solution
使用差分数组标记杀手是否被射杀。因为没有莓果躲弹王,每个杀手 diff[start]++,diff[end+1]--;,最后对
Code
#include<iostream>
#include<cstdio>
using namespace std;
int n,l[1000001],diff[1000001]={},start,ed,cnt=0;
int main(){
cin>>n;
for(int i=1;i<=n;++i){
cin>>l[i];
start=max(1,i-l[i]),ed=i-1;
if(ed>=start)
diff[start]++,diff[ed+1]--;
}
for(int i=1;i<=n;++i){
diff[i]+=diff[i-1];
if(diff[i]==0)
cnt++;
}
cout<<cnt<<"\n";
return 0;
}
非倍数
Problem
描述
小海狸给你两个数
输入描述
唯一的行包含两个整数
输出描述
输出最大整数。 如果没有,输出 -1。
用例输入 1
3 6
用例输出 1
5
用例输入 2
3 4
用例输出 2
-1
提示
子任务一:
子任务二:
子任务三:
Solution
若
当
因此可以用埃氏筛求出不超过 -1。
Code
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int k,n;
int main(){
cin>>k>>n;
for(int i=n;i>k;--i){
bool flag=1;
for(int j=2;j<=min(k,int(sqrt(i)));++j){
if(i%j==0){
flag=0;
break;
}
}
if(flag==1){
cout<<i<<"\n";
return 0;
}
}
cout<<"-1\n";
return 0;
}
两个键盘
Problem
描述
小海狸有两个键盘,它们的按键有所不同:它们仅在字母的位置上有所不同,其他所有键均相同。大小写字母在键盘中的位置是一样的。
小海狸向你展示了两个字符串,每个字符串由
输入描述
第一行包含一个长度为
第二行包含长度为
第三行包含一个由大小写英文字母和数字组成的非空字符串。这是在第一个键盘中键入的文本,长度不超过
输出描述
打印要在第二个键盘键入的文本。
用例输入 1
qwertyuiopasdfghjklzxcvbnm
veamhjsgqocnrbfxdtwkylupzi
TwccpQZAvb2017
用例输出 1
HelloVKCup2017
用例输入 2
mnbvcxzlkjhgfdsapoiuytrewq
asdfghjklqwertyuiopzxcvbnm
7abaCABAABAcaba7
用例输出 2
7uduGUDUUDUgudu7
提示
子任务一:
子任务二:
子任务三:
Solution
可以直接用字符串处理,也可以用
Code
#include<iostream>
#include<cstdio>
using namespace std;
string a,b,s;
int main(){
cin>>a>>b>>s;
for(int i=0;i<s.length();++i){
if(s[i]>='A'&&s[i]<='Z'){
for(int j=0;j<26;++j){
if(s[i]==(char)(a[j]-32)){
cout<<(char)(b[j]-32);
break;
}
}
}
else if(s[i]>='a'&&s[i]<='z'){
for(int j=0;j<26;++j){
if(s[i]==a[j]){
cout<<b[j];
break;
}
}
}
else
cout<<s[i];
}
cout<<"\n";
return 0;
}
小海狸的兴趣班
Problem
描述
小海狸喜欢下象棋,也喜欢编程,所以他决定参加象棋班和编程班。象棋班课程有
小海狸需要选择参加象棋班的
小海狸想知道在最好的情况下两个课程之间的最长休息时间。
输入描述
输入的第一行包含一个整数
输入的以下n行中的每行都包含两个整数
接下来一行包含一个整数
输入的以下
输出描述
输出一个整数,表示两个时间段之间的最大距离,即最长休息时间。
用例输入 1
3
1 5
2 6
2 3
2
2 4
6 8
用例输出 1
3
用例输入 2
3
1 5
2 6
3 7
2
2 4
1 4
用例输出 2
0
提示
子任务一:
子任务二:
子任务三:
在第一个示例中,可以在时段(
在第二个示例中,他选择任意一对时段都会相交。 因此答案是
Soluntion
由贪心可知,选最小的结束时间和最大的开始时间可以有最长的课间,同时在两种顺序中取较大值即可。
Code
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,cn=2e9,px=0,pn=2e9,cx=0;
struct cls{
int start,ed;
}a[200005],b[200005];
int main(){
cin>>n;
for(int i=1;i<=n;++i){
cin>>a[i].start>>a[i].ed;
cn=min(cn,a[i].ed);
cx=max(cx,a[i].start);
}
cin>>m;
for(int i=1;i<=m;++i){
cin>>b[i].start>>b[i].ed;
pn=min(pn,b[i].ed);
px=max(px,b[i].start);
}
cout<<max(max(0,px-cn),max(0,cx-pn))<<"\n";
return 0;
}