201403-1
解题思路:数据量较小,直接暴力枚举
参考代码
#include<bits/stdc++.h>
using namespace std;
const int N = 5e2 + 5;
int n;
int a[N];
int ans;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (a[i] + a[j] == 0) ans++;
}
}
cout << ans;
return 0;
}
201403-2
解题思路:数据量比较小,直接模拟,每次从上往下找满足的窗口,用两个栈实现窗口的转移
参考代码
#include<bits/stdc++.h>
using namespace std;
const int N = 1e1 + 5;
int n, m;
struct node {
int id;
int x1, y1;
int x2, y2;
} a[N];
stack<node>s1, s2;
node ans;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
a[i].id = i;
cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
s1.push(a[i]);
}
int x, y, is;
for (int i = 1; i <= m; i++) {
cin >> x >> y;
is = 0;
while (!s1.empty()) {
node now = s1.top();
s1.pop();
if (x >= now.x1 && x <= now.x2 && y >= now.y1 && y <= now.y2) {
ans = now;
cout << now.id << endl;
is = 1;
break;
}
s2.push(now);
}
if (!is) cout << "IGNORED" << endl;
while (!s2.empty()) {
s1.push(s2.top());
s2.pop();
}
if (is) s1.push(ans);
}
return 0;
}
201403-3
解题思路:模拟
参考代码
#include<bits/stdc++.h>
using namespace std;
const int N = 30;
bool isnt[N], is[N];
int n;
string s;
string ans[N];
int main() {
cin >> s;
for (int i = 0; i < s.size(); i ++) {
if (i + 1 < s.size() && s[i + 1] == ':') {
is[s[i] - 'a'] = 1;
i ++;
} else {
isnt[s[i] - 'a'] = 1;
}
}
cin >> n;
getchar();
for (int C = 1; C <= n; C ++) {
printf("Case %d:", C);
getline(cin, s);
string t;
stringstream ssin(s);
vector <string> ops;
while (ssin >> t) ops.push_back(t);
for (int i = 0; i < 26; i ++) ans[i].clear();
for (int i = 1; i < ops.size(); i ++) {
if (ops[i][0] != '-' || ops[i][1] < 'a' || ops[i].size() != 2) break;
int k = ops[i][1] - 'a';
if (isnt[k]) {
ans[k] = '*';
} else if (is[k] && i + 1 < ops.size()) {
ans[k] = ops[i + 1];
i ++;
} else break;
}
for (int i = 0; i < 26; i ++) {
if (ans[i].size()) {
cout << " -" << char('a' + i);
if (is[i]) {
cout << ' ' << ans[i];
}
}
}
cout << endl;
}
return 0;
}
201403-4
解题思路:
参考代码
201403-5
解题思路:
参考代码