1、报数
ACwing 3282
#include <iostream>
#include <algorithm>
using namespace std;
int ans[4];
int main() {
int n; cin >> n;
int k = 0, i = -1;
while (n) {
i++, k++;
if (k % 7 == 0 || to_string(k).find('7') != -1) ans[i % 4]++;
else n--;
}
for (int i = 0; i < 4; i++) cout << ans[i] << endl;
return 0;
}
2、回收站选址
ACwing 3283
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
#define x first
#define y second
typedef pair<int, int> PII;
int n;
int ans[5];
set<PII> st;
int dx[] = {0, -1, 0, 1}, dy[] = {-1, 0, 1, 0};
int ix[] = {-1, -1, 1, 1}, iy[] = {-1, 1, 1, -1};
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int x, y; cin >> x >> y;
st.insert({x, y});
}
for (auto it: st) {
int cnt = 0;
for (int j = 0; j < 4; j++) {
int a = it.x + dx[j], b = it.y + dy[j];
if (st.count({a, b})) cnt++;
}
if (cnt != 4) continue;
int sum = 0;
for (int j = 0; j < 4; j++) {
int a = it.x + ix[j], b = it.y + iy[j];
if (st.count({a, b})) sum++;
}
ans[sum]++;
}
for (int an : ans) cout << an << endl;
return 0;
}
3、化学方程式
ACwing 3284
4、区块链
ACwing 3285
#include <iostream>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <vector>
#include <queue>
using namespace std;
typedef vector<int> VI;
const int N = 510, M = 20010;
int n, m, w, Q;
int h[N], e[M], ne[M], idx;
vector<VI> g;
int node[N];
struct Op {
int t, id, pid, hid;
bool operator<(const Op &r) const {
return t > r.t;
}
};
priority_queue<Op> heap;
void add(int a, int b) {
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
void eval() {
auto t = heap.top(); heap.pop();
auto &a = g[node[t.id]], &b = g[t.hid];
if (b.size() > a.size() || b.size() == a.size() && b.back() < a.back()) {
node[t.id] = t.hid;
for (int i = h[t.id]; ~i; i = ne[i])
if (e[i] != t.pid && e[i] != t.id)
heap.push({t.t + w, e[i], t.id, t.hid});
}
}
int main() {
scanf("%d%d", &n, &m);
g.push_back({0});
memset(h, -1, sizeof h);
while (m--) {
int a, b; scanf("%d%d", &a, &b);
add(a, b), add(b, a);
}
scanf("%d%d", &w, &Q); getchar();
char str[100];
while (Q--) {
fgets(str, 100, stdin); stringstream ssin(str);
int a[3], cnt = 0;
while (ssin >> a[cnt]) cnt++;
if (cnt == 3) {
while (heap.size() && heap.top().t <= a[1]) eval();
g.push_back(g[node[a[0]]]);
g.back().push_back(a[2]);
node[a[0]] = g.size() - 1;
for (int i = h[a[0]]; ~i; i = ne[i])
if (e[i] != a[0])
heap.push({a[1] + w, e[i], a[0], node[a[0]]});
} else {
while (heap.size() && heap.top().t <= a[1]) eval();
printf("%d ", g[node[a[0]]].size());
for (auto x: g[node[a[0]]]) printf("%d ", x);
puts("");
}
}
return 0;
}