第四次双周赛补题

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
int main() {
	cout << "I'm gonna WIN!" << endl;
	cout << "I'm gonna WIN!" << endl;
	cout << "I'm gonna WIN!" << endl;
}

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
int main() {
	string a;
	cin >> a;
	string b, c, d;
	int panduan = 1;
	for (int e = 0; e < a.size(); e++) {
		if (a[e] == '-') {
			panduan++;
			continue;
		}
		if (panduan == 1) {
			b += a[e];
		}
		else if(panduan==2){
			c += a[e];
		}
		else {
			d += a[e];
		}
	}
	cout << d << "-" << b << "-" << c;
}

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	scanf("%d:%d", &a, &b);
	if (b > 0) {
		a += 1;
	}
	//cout << "Only 07:05.  Too early to Dang."<<endl;
	if (a <= 12 && a >= 0) {
		if (b > 0) {
			a -= 1;
		}
		cout << "Only ";
		if (a < 10) {
			cout << 0 << a<<":";
		}
		else {
			cout << a << ":";
		}
		if (b < 10) {
			cout << 0 << b;
		}
		else {
			cout << b;
		}
		cout << ".  Too early to Dang.";
		return 0;
	}
	for (int e = 0; e < a-12; e++) {
		cout << "Dang";
	}
}

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
long long int hhh(int x) {
	if (x == 1) {
		return 1;
	}
	return hhh(x - 1)*x;
}
int main() {
	int a, b;
	cin >> a >> b;
	cout<<hhh(a + b);
}

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
int hhh[10];
int main() {
	string a;
	cin >> a;
	for (int e = 0; e < a.size(); e++) {
		hhh[a[e] - '0']++;
	}
	for (int e = 0; e < 10; e++) {
		if (hhh[e] > 0) {
			cout << e << ":" << hhh[e] << endl;
		}
	}
}

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
int c = 0, d = 0;
string a,b;
int hhh(string x) {
	for (int e = 0; e < x.size(); e++) {
		if (e == 0 && x[e] == '0') {
			return 0;
		}
		if (x[e] > 57 || x[e] < 48) {
			return 0;
		}
	}
	int h = 0;
	for (int e = 0; e < x.size(); e++) {
		h *= 10;
		h += x[e] - '0';
	}
	if (h > 1000||h==0) {
		return 0;
	}
	return 1;
}
int main() {
	string t;
	getline(cin,t);
	int hjk = 1;
	for (int e = 0; e < t.size(); e++) {
		if (t[e] == ' ') {
			hjk++;
			continue;
		}
		if (hjk == 1) {
			a += t[e];
		}
		else if(hjk==2) {
			b += t[e];
		}
	}
	if (hjk > 2) {
		if (hhh(a)) {
			cout << a << " + ";
		}
		else {
			cout << "?" << " + ";
		}
		cout << "?" << " = ";
		cout << "?";
		return 0;
	}
	if (hhh(a)) {
		cout << a << " + ";
	}
	else {
		cout << "?" << " + ";
	}
	if (hhh(b)) {
		cout << b << " = ";
	}
	else {
		cout << "?" << " = ";
	}
	if (hhh(a) && hhh(b)) {
		for (int e = 0; e < a.size(); e++) {
			c *= 10;
			c += a[e] - '0';
		}
		for (int e = 0; e < b.size(); e++) {
			d *= 10;
			d += b[e] - '0';
		}
		cout << c + d;
	}
	else {
		cout << "?";
	}
}

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

int main() {
	int x;
	string y;
	cin >> x >> y;
	int hh =0;
	int n;
	for (n = 1;hh<=x; n+=2) {
		hh = (1 + n) * (n + 1) / 2 - 1;
		//cout << hh << endl;
	}
	n -= 4;
	for (int e = n; e >= 1; e -= 2) {
		for (int i =( n - e)/2; i > 0; i--) {
			cout << " ";
		}
		for (int i = e; i > 0; i--) {
			cout << y;
		}
		cout << endl;
	}
	for (int e = 3; e <= n; e += 2) {
		for (int i = (n - e) / 2; i > 0; i--) {
			cout << " ";
		}
		for (int i = e; i > 0; i--) {
			cout << y;
		}
		cout << endl;
	}
		cout << x -((1 + n) * (n + 1) / 2 - 1);
}

思路:

用map存不能走的格子,之后用总数量减去map的size

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
map<pair<int, int>,int>hhh;
int main() {
	long long int a, b,c;
	cin >> a >> b >> c;
	for (int e = 0; e < c; e++) {
		int x,y;
		cin >> x >> y;
		if (x == 0) {
			for (int i = 1; i <=b;i++) {
				hhh[make_pair(y, i)] = 1;
			}
		}
		else {
			for (int i = 1; i <=a; i++) {
				hhh[make_pair(i, y)] = 1;
			}
		}
	}
	cout << a * b - hhh.size();
}

思路:

 hhh录入数据,hao记录好朋友,全部记录完之后把hao数组全部取并集,之后就是if else

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
map<pair<int, int>, int>hhh;
vector<vector<int>>hao;
vector<int> vectors_set_union(vector<int> v1, vector<int> v2) {
	vector<int> v;
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(v));//求交集 
	return v;
}
int main() {
	hao.resize(1000);
	long long int a, b, c;
	cin >> a >> b >> c;
	for (int e = 0; e < b; e++) {
		int x, y, z;
		cin >> x >> y >> z;
		if (z == 1) {
			hao[x].push_back(y);
			hao[y].push_back(x);
		}
		hhh[make_pair(x, y)] = z;
		hhh[make_pair(y, x)] = z;
	}
	for (int e = 0; e < hao.size(); e++) {
		for (int h = 0; h < hao[e].size(); h++) {
			hao[e] = vectors_set_union(hao[e], hao[hao[e][h]]);
		}
	}
	for (int e = 0; e < c; e++) {
		int x, y;
		cin >> x >> y;
		if (hhh[make_pair(x, y)] == 0) {
			cout << "OK" << endl;
			continue;
		}
		if (hhh[make_pair(x, y)] == 1) {
			cout << "No problem" << endl;
			continue;
		}
		int haopu = 0;
		for (int p = 0; p < hao[x].size(); p++) {
			if (haopu) {
				break;
			}
			for (int i = 0; i < hao[y].size(); i++) {
				if (hao[x][p] == hao[y][i]) {
					haopu++;
				}
			}
		}
		if (haopu) {
			cout << "OK but..." << endl;
		}
		else {
			cout << "No way" << endl;
		}
	}
}

思路:

用pair的动态数组存数据,之后用sort排序,输出 

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
vector<pair<int, string>>hhh;
bool cmp(const pair<int, string>a, pair<int, string>b) {
	return a.first > b.first || (a.first == b.first && a.second < b.second);
}
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	for (int e = 0; e < a; e++) {
		int x; string y;
		cin >> y >> x;
		hhh.push_back(make_pair(x, y));
	}
	int mony = 0;
	for (int e = 0; e < hhh.size(); e++) {
		if (hhh[e].first >= b) {
			mony += 50;
		}
		else if (hhh[e].first >= 60) {
			mony += 20;
		}
	}
	cout << mony << endl;
	sort(hhh.begin(), hhh.end(), cmp);
	int cishu = 1;
	int jilu = hhh[0].first;
	int zh = 0;
	for (int e = 0; e < hhh.size(); e++) {
		if (jilu != hhh[e].first) {
			jilu = hhh[e].first;
			cishu += zh;
			zh = 1;
			if (cishu > c) {
				return 0;
			}
			cout << cishu << " " << hhh[e].second << " " << hhh[e].first << endl;
		}
		else {
			zh++;
			cout << cishu << " " << hhh[e].second << " " << hhh[e].first << endl;
		}
	}
}

 思路:

开一个动态数组存轨道,一个stack存包裹

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<Windows.h>
using namespace std;
vector<string>a;
stack<char>b;
int main() {
	int a7, a8, a9;
	string ans;
	cin >> a7 >> a8 >> a9;
	a.push_back("0");
	for (int e = 1; e <=a7; e++) {
			string a10;
			cin >> a10;
			a.push_back(a10);
	}
	/*for (int e = 1; e < a.size(); e++) {
		cout << a[e] << endl;
	}*/
	while (1) {
		int a11;
		cin >> a11;
		if (a11 == -1) {
			break;
		}
		if (a11 == 0) {
			if (b.empty()) {

			}
			else {
				ans += b.top();
				b.pop();
			}
		}
		else {
			if(a[a11].empty()){

			}
			else {
				if (b.size() == a9) {
					ans += b.top();
					b.pop();
					b.push(a[a11].front());
					a[a11].erase(a[a11].begin());
				}
				else {
					b.push(a[a11].front());
					a[a11].erase(a[a11].begin());
				}
			}
		}
	}
	cout << ans;
}

 

 思路:

用一个二维数组接受数据,建立树然后搜索,用另一个数组记录每个人是否被提到,如果一个人被提到两次,说明他们五代之内有近亲,所以不行.切记每次要初始化数据.

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
int xinxi[1000000][3];
int jilu[1000000];
int panduan = 1;
void dfs(int a, int b) {
	if (a > 5) {
		return;
	}
	if (!panduan) {
		return;
	}
	if (b == -1) {
		return;
	}
	if (b == 0) {
		return;
	}
	if (jilu[b] != 0) { panduan = 0; }
	else {
		jilu[b]++;
	}
	if (xinxi[b][1] != -1) {
		dfs(a + 1, xinxi[b][1]);
	}
	if (xinxi[b][2] != -1) {
		dfs(a + 1, xinxi[b][2]);
	}
}
int main() {
	for (int e = 0; e < 1000000; e++) {
		xinxi[e][0] = -1;
	}
	int n;
	cin >> n;
	for (int e = 0; e < n; e++) {
		int a, c, d;
		string b;
		cin >> a >> b >> c >> d;
		xinxi[a][1] = c;
		xinxi[a][2] = d;
		if (c != -1) {
			xinxi[c][0] = 1;
		}
		if (d != -1) {
			xinxi[d][0] = 0;
		}
		if (b == "M") {
			xinxi[a][0] = 1;//男
		}
		else {
			xinxi[a][0] = 0;//女
		}
	}
	cin >> n;
	for (int e = 0; e < n; e++) {
		int a, b;
		cin >> a >> b;
		memset(jilu, 0, sizeof(jilu));
		/*for (int i = 0; i < 1000000; i++) {
			jilu[i] = 0;
		}*/
		panduan = 1;
		if (xinxi[a][0] == xinxi[b][0] && xinxi[a][0] != -1) {
			cout << "Never Mind" << endl;
			continue;
		}
		dfs(1, a);
		dfs(1, b);
		if (panduan) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

唏嘘南溪

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

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

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

打赏作者

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

抵扣说明:

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

余额充值