【ABC】AtCoder Beginner Contest 261 C++代码

A - Intersection

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mo = 1e3;
const int N = 1e5+5;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int kk=max(a,c);
	int tt=min(b,d);
	if(kk<tt) cout<<tt-kk;
	else cout<<0;
	return 0;
}

B - Tournament Result 

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mo = 1e3;
const int N = 1010;
char a[N][N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = i+1; j <= n; j++)
		{
			int k=a[j][i];
			char gg;
			if(k=='W')gg='L';
			else
			if(k=='L')gg='W';
			else
			gg='D';
			if (a[i][j]!=gg)
			{
				cout<<"incorrect";
				return 0;
			}
		}
	}
	cout<<"correct";
	return 0;
}

C - NewFolder(1)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mo = 1e3;
const int N = 2e5 + 5;
map<string, int> mp;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	string s;
	while (t--)
	{
		cin >> s;
		map<string, int> ::iterator it= mp.find(s);
		if (it != mp.end())
		{
			mp[s]++;
			cout<<s<<'('<<mp[s]<<')'<<'\n';
		}
		else
		{
			cout<<s<<'\n';
			mp[s]=0;
		}
	}
	return 0;
}

D - Flipping and Bonus

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mo = 1e3;
const int N = 5000 + 5;
ll f[N][N], a[N], b[N];
//f[i][j]表示前i个硬币,当前是连续第i次,所能得到的最大价值
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	memset(f,0,sizeof(0));
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	int c, y;
	for (int i = 1; i <= m; i++)
	{
		cin >> c >> y;
		b[c] = y;
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= i; j++)
		{
			f[i][j] = max(f[i - 1][j - 1] + a[i] + b[j], f[i][j]);
			f[i+1][0] = max(f[i][j], f[i+1][0]);
			//cout << i << ' ' << j << ' ' << f[i][j] << endl;
		}
	}
	ll ans = 0;
	for (int j = 1; j <= n; j++)
	{
		ans = max(f[n][j], ans);
	}
	cout << ans;
	return 0;
}

E - Many Operations

输入是一个一个操作输入的,但我们可以全部输入完之后按位处理。最后统一输出

#include<bits/stdc++.h>
using namespace std;
#define bit(x,i)(((x)>>(i))&1)
int main(){
	int n,c;
	cin >> n >> c;
	vector<pair<int,int>>op(n);
	for(int i=0;i<n;i++)cin >> op[i].first >> op[i].second;
	vector<int>ans(n);
	for(int k=0;k<30;k++){
		array<int,2>func={0,1};
		int crr=bit(c,k);
		for(int i=0;i<n;i++){
			array<int,2>f;
			int x=bit(op[i].second,k);
			if(op[i].first==1)f={0&x,1&x};
			if(op[i].first==2)f={0|x,1|x};
			if(op[i].first==3)f={0^x,1^x};
			func={f[func[0]],f[func[1]]};
			crr=func[crr];
			ans[i]|=crr<<k;
		}
	}
	for(int i=0;i<n;i++)cout << ans[i] << endl;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值