Codeforces Round #799 (Div. 4)A~H

一系列编程题目集锦,包括马拉松比赛名次计算、数组中全不相同的元素数量、判断象棋棋盘上bishop的位置、分析时钟显示相同数字的间隔、双端队列操作、寻找数组中三数之和等于特定值的情况、按2的幂进行排序及赌博游戏的概率分析。

A. Marathon

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
void solve()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int res=0;
	if(b>a)res++;
	if(c>a)res++;
	if(d>a)res++;
	cout<<res<<endl;
}
signed main()
{
	io;
	cin>>_;	
	while(_--)
	solve();
	return 0;
}

B. All Distinct

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
const int N=51;
int a[N];
void solve()
{
	cin>>n;
	map<int,int>mp;
	for(int i=1;i<=n;i++)cin>>a[i],mp[a[i]]++;
	int res=0;
	for(auto x:mp)
	{
		if(x.y>=2)res+=x.y-1;
	}
	if(res%2)cout<<mp.size()-1<<endl;
	else cout<<mp.size()<<endl;
	
}
signed main()
{
	io;
	cin>>_;	
	while(_--)
	solve();
	return 0;
}

C. Where’s the Bishop?

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
const int N=10;
char g[N][N];
void solve()
{
	n=8;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>g[i][j];
	for(int i=2;i<n;i++)
		for(int j=2;j<n;j++)
			if(g[i][j]=='#')
			{
				if(g[i-1][j-1]=='#'&&g[i-1][j+1]=='#'&&g[i+1][j-1]=='#'&&g[i+1][j+1]=='#')
				{
					cout<<i<<' '<<j<<endl;
					return;
				}
			}
}
signed main()
{
	io;
	cin>>_;	
	while(_--)
	solve();
	return 0;
}

D. The Clock

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
void solve()
{
	int x;
	char c;
	int h,m;
	cin>>h>>c>>m>>x;
	map<int,int>mp;
	int res=0;
	int now=h*60+m;
	while(1)
	{
	    //cout<<now<<endl;
	    if(mp.count(now))break;
	    else mp[now]++;
	    int a=now/60,b=now-a*60;
	    int r=0;
	    int bs=b;
	    for(int i=0;i<2;i++)
	    {
	        r=r*10+bs%10;
	        bs/=10;
	    }
	    if(a==r)res++;
	    now+=x;
	    if(now>=1440)now-=1440;
	}
	cout<<res<<endl;
}
signed main()
{
	io;
	cin>>_;	
	while(_--)
	solve();
	return 0;
}

E. Binary Deque

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n,sum;
const int N=2e5+10;
int s[N];
int a[N];
int l,r;
int start;
bool check(int x)
{
	return s[x]-s[start-1]<=sum;
}
void solve()
{
	cin>>n>>sum;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
	int cnt=ll_INF;
	if(s[n]<sum)
	{
		cout<<-1<<endl;
		return;
	}
	if(s[n]==sum)
	{
		cout<<0<<endl;
		return;
	}
	for(int i=1;i<=n;i++)
	{
		l=i;
		start=l;
		r=n;
		while(l<r)
		{
			int mid=l+r+1>>1;
			if(check(mid))l=mid;
			else r=mid-1;
		}
		int len=l-i+1;
		cnt=min(cnt,n-len);
	}
	cout<<cnt<<endl;
}
signed main()
{
	io;
	cin>>_;	
	while(_--)
	solve();
	return 0;
}

F. 3SUM

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n,sum;
int a[10];
void solve()
{
	cin>>n;
	memset(a,0,sizeof a);
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		a[x%10]++;
	}
	int res=0;
	for(int i=0;i<=9;i++)
	{
		for(int j=0;j<=9;j++)
		{
			for(int k=0;k<=9;k++)
			{
				if(i==j&&a[i]<2)continue;
				if(j==k&&a[j]<2)continue;
				if(i==k&&a[i]<3)continue;
				if(i==j&&j==k&&a[i]<3)continue;
				if((i+j+k)%10==3&&a[i]&&a[j]&&a[k])res++;
			}
		}
	}
	if(res)puts("YES");
	else puts("NO");
}
signed main()
{
	io;
	cin>>_;	
	while(_--)
	solve();
	return 0;
}

G. 2^Sort

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n,k;
const int N=2e5+10;
int a[N];
bool st[N];
int s[N];
void solve()
{
	memset(st,0,sizeof st);
	memset(s,0,sizeof s);
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<n;i++)
		if(a[i]>=a[i+1]*2)st[i+1]=true;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+st[i];
//	for(int i=1;i<=n;i++)cout<<st[i]<<' ';
//	cout<<endl;
	int res=0;
	for(int i=1;i+k<=n;i++)
	{
		int r=i+k;
		if(s[r]-s[i-1]==0)res++;
		if(s[r]-s[i-1]==1&&s[i]-s[i-1]==1)res++;
	}
	cout<<res<<endl;
}
signed main()
{
	io;
	cin>>_;	
	while(_--)
	solve();
	return 0;
}

H. Gambling

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n,k;
const int N=200010;
int f[N],l[N];
void solve()
{
	cin>>n;
	vector<int>v; 
	map<int,int>mp;
	int res=0;
	int ans=0,rr=0;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		f[i]=1,l[i]=i;
		if(mp.count(x))
		{
			if(f[i]<f[mp[x]]+1-(i-1-mp[x]))
			{
				f[i]=f[mp[x]]+1-(i-1-mp[x]);
				l[i]=l[mp[x]];
			}
		}
		mp[x]=i;
		if(res<f[i])
		{
			res=f[i];
			rr=i;
			ans=x;
		}
	}
	cout<<ans<<' '<<l[rr]<<' '<<rr<<endl;
}
signed main()
{
	io;
	cin>>_;	
	while(_--)
	solve();
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

leimingzeOuO

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值