这场打的稀碎,,读不懂题QWQ
比赛传送门
J - 三国小孩
思路:自己出一张牌,对方也要出一张牌来消除伤害,又因为如果这一回合不能击败对方就投降,所以至少要比对方多一张攻击牌使对方体力值为0,所以m+n>k,等于不符合题意。
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF 0x3f3f3f3f
//判断是否需要开ll!!!
//判断是否需要初始化!!!
const int mod=1e9+7;
ll n,m,k;
int main()
{
// freopen("test.in","r",stdin);
// freopen("output.in", "w", stdout);
cin>>n>>m>>k;
if(m+n>k) cout<<"YES"<<'\n';
else cout<<"NO"<<'\n';
return 0;
}
os:签到题两小时出题,,,读不懂题wwwwww
G - 163小孩
思路:高中排列组合题,列式计算即可:
取6种不同数值的牌:C(13,1);
取5种不同数值的牌:C(13,1)*C(12,4);
取4种不同数值的牌:C(13,1)*C(12,3)+C(13,2)*C(11,2);
取3种不同数值的牌:C(13,1)*C(12,2)+C(13,1)*C(12,1)*C(11,1)+C(13,3);
取2种不同数值的牌:C(13,1)*C(12,1)+C(13,2);
把以上结果相加得到答案直接输出。
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF 0x3f3f3f3f
//判断是否需要开ll!!!
//判断是否需要初始化!!!
const int mod=1e9+7;
int main()
{
// freopen("test.in","r",stdin);
// freopen("output.in", "w", stdout);
cout<<"18395"<<'\n';
return 0;
}
os:hhh可以直接做的题,还是算错了好几遍
I - 兔崽小孩
思路:前缀和,二分查找。把时间段排序,前缀和数组排序,二分查找等于k的下标,判断前缀和-k*时间段段数与p的大小。
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF 0x3f3f3f3f
//判断是否需要开ll!!!
//判断是否需要初始化!!!
const int mod=1e9+7;
const int N=1e6+5;
int n,q;
int a[N],b[N],s[N];
int main()
{
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<n;i++)
b[i]=a[i+1]-a[i];
sort(b+1,b+n);
for(int i=1;i<n;i++)
s[i]=s[i-1]+b[i];
while(q--)
{
int k,p;
scanf("%d%d",&k,&p);
int pos=lower_bound(b+1,b+n,k)-b;
int cnt=n-pos;
ll num=s[n-1]-s[pos-1]-1ll*cnt*k;
if(num>=p) printf("Yes\n");
else printf("No\n");
}
return 0;
}
os:为什么做法看一下就可以明白但是但是想不到呢。。。
A - 疫苗小孩
思路:打0针和1针时没有贡献,可以不考虑,列举第二针pos位置,二分查找pos+k和pos-k的位置,计算最大贡献即可。
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF 0x3f3f3f3f
//判断是否需要开ll!!!
//判断是否需要初始化!!!
const int mod=1e9+7;
const int N=2e6+5;
int n,m,p[N];
ll k,w,q;
char a[N];
int main()
{
// freopen("test.in","r",stdin);
// freopen("output.in", "w", stdout);
cin>>n;
scanf("%s",a+1);
cin>>k>>w>>q;
int cnt=0;
for(int i=1;i<=n;i++)
if(a[i]=='0') p[++cnt]=i;
p[++cnt]=1e9;
p[0]=-1e9;
ll ans=0;
for(int i=1;i<cnt;i++)
{
int pre=lower_bound(p+1,p+1+cnt,p[i]-k)-p;
ll x=w-min(abs(k-(p[i]-p[pre])),abs(k-(p[i]-p[pre-1])))*q;
if(pre==i) x=w-abs(k-(p[i]-p[pre-1]))*q;
if(x<0) x=0;
int thr=lower_bound(p+1,p+1+cnt,p[i]+k)-p;
ll y=w-min(abs(k-(p[thr]-p[i])),abs(k-(p[thr-1]-p[i])))*q;
if(thr-1==i) y=w-abs(k-(p[thr]-p[i]))*q;
if(y<0) y=0;
ans=max(ans,x+y);
}
cout<<ans<<'\n';
return 0;
}
os:二分查找接连用了两次,以后做题要想到二分这个方法,,,话说这个题目背景hhhhhh
D - 数位小孩
思路:dfs爆搜区间内满足条件的数,计数即可。
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF 0x3f3f3f3f
//判断是否需要开ll!!!
//判断是否需要初始化!!!
const int mod=1e9+7;
const int N=1e7+5;
ll l,r,an[N];
bool p[N];
int cnt;
void dfs(ll x,int f)
{
if(x>r) return;
if(f) an[++cnt]=x;
int pre=x%10;
for(int i=0;i<=9;i++)
{
if(p[i+pre]) dfs(x*10+i,f|(i==1));
}
}
int main()
{
// freopen("test.in","r",stdin);
// freopen("output.in", "w", stdout);
cin>>l>>r;
p[2]=p[3]=p[5]=p[7]=p[11]=p[13]=p[17]=1;
for(int i=1;i<=9;i++)
dfs(i,i==1);
int ans=0;
for(int i=1;i<=cnt;i++)
if(an[i]>=l) ans++;
cout<<ans<<'\n';
return 0;
}
os:dfs灵活运用~
若有错误请指教orzorz