10.30校赛补题

C.骰子

骰子的六个面看成三对(上下,前后,左右),只要两个骰子有一对不相同,就不是相同的,否则相同。

#include<iostream>

using namespace std;

int a[8], b[8];//分别记录每一对的两面

int main() {
	int flag = 1;
	for (int i = 1; i < 4; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 1; i < 4; i++) {
		int x, y;
		cin >> x >> y;
		if (flag) {
			for (int j = 1; j < 4; j++) {
				if ((x == a[j] && y != b[j]) || (x == b[j] && y != a[j])) {
                    //若有一对中的一面不同,则不是同一个
					flag = 0;
					break;
				}
			}
		}
	}
	if (flag) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

​​​​​​E.欢迎参加第二届数云图杯程序设计竞赛

#include<iostream>

using namespace std;

int main(){
    cout<<"QFNU"<<endl;
    return 0;
}

F.躲避攻击(easy version)

直接暴力。。。

#include<iostream>
#include<string>

using namespace std;

int n, k;
char s[100010];

int main() {
	cin >> n >> k >> s;
	while (k--) {
		int x, y;
		cin >> x >> y;
		for (int i = x; i <= y; i++) s[i - 1] = '.';
	}
	for (int i = 0; i < n; i++) {
		if (s[i] == '#') {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

H.放棋子

#include<iostream>

using namespace std;

typedef long long ll;

ll n, m, a;

int main() {
	cin >> n >> m >> a;
	cout << (n / a) * (m / a) << endl;
	return 0;
}

I.斗地主

想了半天的DFS,结果是很离谱的暴力。。。

#include<iostream>

using namespace std;

int n;

int main() {
	cin >> n;
	for (int a = 0; a <= n / 4; a++) {
		for (int b = 0; b <= n / 5; b++) {
			for (int c = 0; c <= n / 6; c++) {
				for (int d = 0; d <= n / 7; d++) {
					for (int e = 0; e <= n / 8; e++) {
						if (a * 4 + b * 5 + c * 6 + d * 7 + e * 8 == n) {
							cout << a << " " << b << " " << c << " " << d << " " << e << endl;
							return 0;
						}
					}
				}
			}
		}
	}
	cout << (-1) << endl;
	return 0;
}

K.多项式

简单的括号匹配问题,'('就入栈,若是')'且栈不为空,则弹出且ans加一,表示匹配。

#include<iostream>
#include<stack>

using namespace std;

stack<int> s;//存放左括号
int n, ans = 0;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		char ch;
		cin >> ch;
		if (ch == '(') s.push(1);
		else {
			if (!s.empty()) {//不为空则配对,对应弹出
				ans++;
				s.pop();
			}
		}
	}
	cout << (ans - (n - ans * 2)) << endl;
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值