骰子的六个面看成三对(上下,前后,左右),只要两个骰子有一对不相同,就不是相同的,否则相同。
#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;
}
#include<iostream>
using namespace std;
int main(){
cout<<"QFNU"<<endl;
return 0;
}
直接暴力。。。
#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;
}
#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;
}
想了半天的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;
}
简单的括号匹配问题,'('就入栈,若是')'且栈不为空,则弹出且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;
}