Codeforces Round #806 (Div. 4)(A.B.C.D.E.F)

A. YES or YES?

题目链接:

Problem - A - Codeforces

题面:

 

题意: 

给定一个长度为3的字符串,问这个字符串是否是“yes",不考虑大小写

思路:

用if判断一下即可

代码:

#include<bits/stdc++.h>
using namespace std;


int main(){
	int t;
	cin >> t;
	while(t--){
		string s;
		cin >> s;
		if((s[0] == 'Y' || s[0] == 'y') && (s[1] == 'E' || s[1] == 'e') && (s[2] == 'S' || s[2] == 's')){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
} 

B. ICPC Balloons

题目链接:

Problem - B - Codeforces

题面:

 

题意: 

给定一个字符串,表示几个队伍的总过题,不会重复提交,问一个发出去了几个气球

注解:第一组样例的第一个A,是一血题,所以发出去2个球,B也是,一共三个球

思路:

遍历一下字符串,如果这个字母是第一次出现的就累加2并且标记一下,不然就累计1

代码:

#include<bits/stdc++.h>
using namespace std;


int main(){
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		string s;
		cin >> s;
		map<char, int> mp;
		int ans = 0;
		for(int i = 0; i < s.length(); i++){
			if(mp[s[i]] == 0){
				mp[s[i]] = 1;
				ans += 2;
			}else{
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C. Cypher

题目链接:

Problem - C - Codeforces

题面:

 

 

 题意:

一个n位的锁,现在给定每位的最终状态,接下来又n行,每行m个字母,'U'表示向上翻,'D'表示向下翻,现在求最初的状态

思路:

'U'是向上,使值+1,如果应用在9上面会变成0,

‘R'是向下,使值-1,如果应用在0上面会变成9,

我们的原数组是结果,我们要求初始状态,我们反向操作即可

入股遇到‘U’,就进行-1操作,‘R’同理

代码:

#include<bits/stdc++.h>
using namespace std;

int arr[105];

int main(){
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		for(int i = 0; i < n; i++){
			cin >> arr[i];
		}
		string s;
		int m;
		
		for(int i = 0; i < n; i++){
			cin >> m >> s;
			for(int j = 0; j < m; j++){
				if(s[j] == 'U'){
					arr[i]--;
					if(arr[i] < 0){
						arr[i] = 9;
					}
				}else{
					arr[i]++;
					if(arr[i] == 10){
						arr[i] = 0;
					}
				}
			}
		}
		for(int i = 0; i < n; i++){
			if(i != 0){
				cout << " ";
			}
			cout << arr[i];
		}
		cout << endl;
	}
	return 0;
}

D. Double Strings

题目链接:

Problem - D - Codeforces

题面:

 

题意: 

给定n个字符串,判断每个字符串能否由两个字符串组成,如果可以输出1,不行输出0

思路:

我们可以永map把给定的每个字符串给标记起来,然后对于每个字符串,我们可以枚举每个分段点,判断分段点前后的字符串是否都存在,如果存在就输出1,如果没有一个分段点可行就输出0

代码:

#include<bits/stdc++.h>
using namespace std;

string s[100005];

int main(){
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		map<string, int> mp;
		for(int i = 0; i < n; i++){
			cin >> s[i];
			mp[s[i]] = 1;
		}
		for(int i = 0; i < n; i++){
			bool f = 0;
			for(int j = 0; j < s[i].length(); j++){
				string a = s[i].substr(0, j + 1);
				string b = s[i].substr(j + 1);
				if(mp[a] && mp[b]){
					cout << 1;
					f = 1;
					break;
				}
			}
			if(f == 0){
				cout << 0;
			}
		}
		cout << endl;
		
	}
	return 0;
} 

E. Mirror Grid

题目链接:

Problem - E - Codeforces

题面: 

 

 题意:

一个二维矩阵由0,1组成,可以进行操作,把0变成1,把1变成0,问最少需要几次操作才能把这个矩阵变成旋转0度,90度,180度,270度都相同的矩阵

思路:

我们可以判断每个点和他三次旋转后的位置的值是否相同即可

 

代码:

#include<bits/stdc++.h>
using namespace std;

string s[105];
bool vis[105][105];

int solve(int x, int y, int n){
	int a = 0, b = 0;
	vis[x][y] = 1;
	vis[y][n - x - 1] = 1;
	vis[n - x - 1][n - y - 1] = 1;
	vis[n  - 1 -y][x] = 1;
	if(s[x][y] == '1'){
		a++;
	}else{
		b++;
	}
	if(s[y][n - x- 1] == '1'){
		a++;
	}else{
		b++;
	}
	if(s[n - 1 - x][n - 1 - y] == '1'){
		a++;
	}else{
		b++;
	}
	if(s[n - y - 1][x] == '1'){
		a++;
	}else{
		b++;
	}
	return 4 - max(a, b);
}

int main(){
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		memset(vis, 0, sizeof(vis));
		for(int i = 0; i < n; i++){
			cin >> s[i];
		}
		int ans = 0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(vis[i][j] == 0){
					ans += solve(i, j, n);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

F. Yet Another Problem About Pairs Satisfying an Inequality

题目链接: 

Problem - F - Codeforces

题面:

 

题意: 

给定一个数组,求里面有几组i,j(满足ai < i < aj < j)

思路:

我们遍历数组,可以找到满足ai < i的数,然后用一个vector去存储位置,然后去找vector里面有几个位置是小于ai的,累加即可

代码:

#include<bits/stdc++.h>
using namespace std;


int main(){
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		long long ans = 0;
		vector<int> ve;
		for(int i = 1; i <= n; i++){
			int a;
			cin >> a;
			if(a < i){
				ans += lower_bound(ve.begin(), ve.end(), a) - ve.begin();
				ve.push_back(i);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值