Codeforces Round #784 (Div. 4)(关于弱弱都能AK的一场比赛)

​​​​​​A. Division?

签到题

AC代码 

#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PII pair<int,int>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
void solve()
{
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		if(n <= 1399) cout << "Division 4" << endl;
		else if(n <= 1599) cout << "Division 3" << endl;
		else if(n <= 1899)cout << "Division 2" << endl;
		else if(n >= 1900) cout << "Division 1" << endl;
	}
}
int main() {
	IOS;
	solve();
	return 0;
}

B. Triple

签到题

AC代码 

#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PII pair<int,int>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
void solve()
{
	int t,n;
	cin >> t;
	while(t--){
		cin >> n;
		vector<int> v(n);
		map <int,int> mp;
		for(auto & x : v){
			cin >> x;
			mp[x]++;
		}
		int flag = 0;
		for(int i = 0 ; i < n ; i++){
			if(mp[v[i]] >= 3){
				flag = 1;
				cout << v[i] << endl;
				break;
			}
		} 
		if(!flag) cout << -1 << endl;
	} 
}
int main() {
	IOS;
	solve();
	return 0;
}

C. Odd/Even Increments

 思路:下标为奇数/偶数位上的奇偶性相同即为YES,否者为NO

AC代码

#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PII pair<int,int>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
void solve()
{
	int t,n;
	cin >> t;
	while(t--){
		cin >> n;
		int a[55];
		for(int i = 1 ; i <= n ; i++){
			cin >> a[i];
			a[i] %= 2;
		}
		set <int> s1,s2;
		for(int i = 1 ; i <= n ; i+=2) s1.insert(a[i]);
		for(int i = 2 ; i <= n ; i+=2) s2.insert(a[i]);
		if(s1.size() == 1 && s2.size() == 1) cout << "YES" << endl;
		else cout << "NO" << endl;
	} 
}
int main() {
	IOS;
	solve();
	return 0;
}

D. Colorful Stamp

 思维题:没遇到一个W,与上一个W之间的B和R必须都有至少一个,可以手动推一推就能得出结论

AC代码

#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PII pair<int,int>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
void solve()
{
	int t,n;
	cin >> t;
	while(t--){
		int n;
		string s;
		cin >> n >> s;
		s += 'W';
		int r = 0,b = 0;
		int flag = 1;
		for(int i = 0 ; i <= n ; i++){
			if(s[i] == 'W'){
				if(b != r) flag = 0;
				r = 0;
				b = 0;
			}
			if(s[i] == 'R') r = 1;
			if(s[i] == 'B') b = 1;
		}
		if(flag) cout << "YES" << endl;
		else cout << "NO" << endl;
	} 
}
int main() {
	IOS;
	solve();
	return 0;
}

E. 2-Letter Strings

 思路:求有多少对只有一个字母不同的组合,一下图解,一眼就懂

    1.两个串不相交明显不符合一对

 2.两个字符串相交

 由于只需要一个不同,至于要两个单独的一个之和减去两个都有的两倍即是答案

AC代码

#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PII pair<int,int>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
void solve()
{
	int t,n;
	cin >> t;
	while(t--){
		cin >> n;
		map <char,int> m1,m2;
		map <string,int> mp;
		ll ans =0 ;
		string s;
		for(int i = 1 ; i <= n ; i++){
			cin >> s;
			ans += m1[s[0]] + m2[s[1]] - 2 * mp[s];
			m1[s[0]]++; m2[s[1]]++; mp[s]++;
		}
		cout << ans << endl;
	} 
}
int main() {
	IOS;
	solve();
	return 0;
}

F. Eating Candies

 思路:要吃的最多,而且还要吃的重量一样,但是关键是题目一个从左边吃,一个从右边吃,可以 前缀和+二分解决 ,关键就是两侧的重量和相等

AC代码

#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PII pair<int,int>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
void solve()
{
	int t,n;
	cin >> t;
	while(t--){
		cin >> n;
		vector <int> v(n + 1),sum(n + 1,0);
		for(int i = 1 ; i <= n ; i++){
			cin >> v[i];
			sum[i] = sum[i - 1] + v[i];
		} 
		int maxlen = 0;
		for(int i = 1 ; i < n ; i++){
			int x = sum[n] - sum[i];
			if(!binary_search(sum.begin() + 1,sum.end(),x)) continue;
			int pos = lower_bound(sum.begin() + 1,sum.end(),x) - sum.begin();
			if(pos < i) continue;
			maxlen = max(maxlen,i + n - pos);
		}
		cout << maxlen << endl;
	} 
}
int main() {
	IOS;
	solve();
	return 0;
}

G. Fall Down

 一个方向的dfs,但是关键是倒着遍历,不然会造成石头还能下落

AC代码

#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PII pair<int,int>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int n,m,t;
char g[100][100];
void dfs(int x,int y)
{
	if(x == n) return ;
	if(x + 1 <= n && g[x + 1][y] == '.'){
		g[x][y] = '.';
		g[x + 1][y] = '*';
		dfs(x + 1,y);
	}
}
void solve()
{
	cin >> t;
	while(t--){
		cin >> n >> m;
	
		for(int i = 1 ; i <= n ; i++) scanf("%s",g[i] + 1);
		for(int i = n ; i >= 1 ; i--){
			for(int j = m ; j >= 1 ; j--){
				if(g[i][j] == '*'){
					dfs(i,j);
				}
			}
		}
		for(int i = 1 ; i <= n ; i++){
			for(int j = 1 ; j <= m ; j++){
				cout << g[i][j];
			}
			cout << endl;
		}
	}
	
}
int main() {
	//IOS;
	solve();
	return 0;
}

H. Maximal AND

 思路:题目让你有k次机会让你把Ai二进制的某个位置变为1,最后与运算最大,要每个数的二进制的每一位为1,与运算才为1,而且还要最大,所以从最高位开始,假如K次机会可以满足当前这一位全为1,则用掉相应的次数,最后在加起来即是答案

AC代码

#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PII pair<int,int>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int n,k,t;
void solve()
{
	cin >> t;
	while(t--){
		cin >> n >> k;
		vector <int> v(n);
		ll ans = 0;
		for(int & x : v) cin >> x;
		for(int i = 30 ; i >= 0 ; i--){
			int cnt = 0;
			for(int j = 0 ; j < n ; j++){
				int alp = (v[j] >> i) & 1;
				if(!alp) cnt++;
			}
			if(k >= cnt){
				k -= cnt;
				ans += 1 << i;
			}
		}
		cout << ans << endl;
	}

	
}
int main() {
	IOS;
	solve();
	return 0;
}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值