Codeforces Round #552 (Div. 3) 补题

A. Restoring Three Numbers
解方程题,很水。

/**/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cctype>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#define mm(i,v) memset(i,v,sizeof i);
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF=99999999999999;
const int inf=999999999;
int a[6];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	for(int i=1;i<=4;i++)
		cin>>a[i];
	sort(a+1,a+5);
	cout<<a[4]-a[1]<<" "<<a[4]-a[2]<<" "<<a[4]-a[3]<<"\n";

	return 0;
}

/*
    summary:
*/

B. Make Them Equal
好气啊,我的B被hack了,头疼!
下面是正确代码。

/**/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cctype>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#define mm(i,v) memset(i,v,sizeof i);
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF=99999999999999;
const int inf=999999999;
int a[200];
set<int> s;

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,x;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		s.insert(x);
	}
	if(s.size()>3)
		cout<<-1<<"\n";
	else if(s.size()==3){
		auto it=s.begin();
		int a=*it;it++;
		int b=*it;it++;
		int c=*it;
		if(c-b==b-a)
			cout<<c-b<<"\n";
		else
			cout<<-1<<"\n";
	}
	else if(s.size()==2){
		auto it=s.begin();
		int a=*it;it++;
		int b=*it;
		if((b-a)%2==0)
			cout<<(b-a)/2<<"\n";
		else
			cout<<b-a<<"\n";
	}
	else
		cout<<0<<"\n";

	return 0;
}

/*
    summary:对于容器的指针还需要多熟悉。
*/

C. Gourmet Cat
这题好气啊,思路想到了,就是最后的细节没想到好的处理办法。然后卡这题了,也没心思去看D。
思路:先把所以的数按3:2:2处理一遍,每一个3:2:2都是一个七天。剩下的数再用一个数组来模拟一周七天,然后枚举七天中每天出门的情况,求最大值。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#define mm(i,v) memset(i,v,sizeof i);
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int a,b,c;
int cat[7]={0,1,2,0,2,1};
int cnt[10];

int slove(int i){
	int ret=0;
	cnt[0]=a,cnt[1]=b,cnt[2]=c;
	// cout<<cnt[0]<<" "<<b<<" "<<cnt<<endl;
	for(int j=i;;j=(j+1)%7){
		if(cnt[cat[j]]){
			ret++;
			cnt[cat[j]]--;
		}
		else
			break;
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int maxx=-1,ans=0;
	cin>>a>>b>>c;
	int aa=a/3,bb=b/2,cc=c/2;
	int t=min(aa,min(bb,cc));
	a-=t*3,b-=t*2,c-=t*2;
	ans+=t*7;
	// cout<<a<<" "<<b<<" "<<c<<endl;
	// cout<<ans<<endl;
	for(int i=0;i<7;i++)
		maxx=max(maxx,slove(i));
	cout<<ans+maxx<<"\n";

	return 0;
}

D. Walking Robot
思路:直接按题意模拟,为0的时候有a先a,不行再b。为1的时候,能充电先充电,不能有a先a,最后才b。

/**/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cctype>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#define mm(i,v) memset(i,v,sizeof i);
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF=99999999999999;
const int inf=999999999;

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,a,b,x,t;
	int ans=0;
	cin>>n>>b>>a;
	t=a;
	for(int i=1;i<=n;i++){
		cin>>x;
		if(x==0){
			if(t>0)
				t--;
			else if(b>0)
				b--;
			else
				break;
		}
		else{
			if(t<a&&b>0){
				b--;
				t++;
			}
			else if(t>0)
				t--;
			else
				break;
		}
		ans++;
	}
	cout<<ans<<"\n";

	return 0;
}

/*
    summary:
*/

E. Two Teams
题意:一队学生站成一排,两个老师选学生,每次选择能力值最大的和他往左数k个,往右数k个。
思路:用pair来存能力值和位置,用链表来删点。

/**/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cctype>
#include <queue>
#include <stack>
#include <cmath>
#include <list>
#include <map>
#include <set>
#define mm(i,v) memset(i,v,sizeof i);
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF=99999999999999;
const int inf=999999999;
const int maxn=2e5+10;

list<pair<int,int> > L;
list<pair<int, int> >::iterator it[maxn];
pair<int,int> a[maxn];
bool vis[maxn];
int ans[maxn];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	int team=1;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i].first;
		a[i].second=i;
		L.push_back(a[i]);
		it[i]=--L.end();
	}
	sort(a+1,a+n+1);
	for(int i=n;i>=1;i--){
		int t=a[i].second;
		if(vis[t])
			continue;
		list<pair<int, int> >::iterator l =it[t],r=it[t];
		for(int j=1;j<=k;j++){
			if(l!=L.begin())
				l--;
			if(r!=--L.end())
				r++;
		}
		r++;
		while(l!=r){
			ans[l->second]=team;
			vis[l->second]=1;
			l=L.erase(l);
		}
		team=3-team;
	}
	for(int i=1;i<=n;i++)
		cout<<ans[i];
	cout<<"\n";

	return 0;
}

/*
    summary:数列掌握链表和pair!
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值