GRYZ20211104 Simulation problem solving report
作者:互联网
Because my English is la, let me try to use English to write this report.
Expect to score:\(100+100+0 \sim 50 = 200 \sim 250pts\)
The actual score:\(100+100+25 = 225pts\)
In front of the report, worship @斜揽残箫
Yeah, how am I supposed to be with God.
I'm just standing on the shoulders of giants.
T1 book
Solution
Simulation is ok,For each \(20\) RMB, the greedy gives \(10\) RMB change first.
Code
/*
Work by: Suzt_ilymtics
Problem: book
Knowledge: Greedy
Time: O(Can AC)
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define LL long long
#define orz cout<<"lkp AK IOI!"<<endl
using namespace std;
const int MAXN = 1e5+5;
const int INF = 1e9+7;
const int mod = 1e9+7;
int n;
int cnt1 = 0, cnt2 = 0, cnt3 = 0;
bool Flag = false;
int read(){
int s = 0, f = 0;
char ch = getchar();
while(!isdigit(ch)) f |= (ch == '-'), ch = getchar();
while(isdigit(ch)) s = (s << 1) + (s << 3) + ch - '0' , ch = getchar();
return f ? -s : s;
}
int main()
{
// freopen("book.in","r",stdin);
// freopen("book.out","w",stdout);
n = read();
for(int i = 1, x; i <= n; ++i) {
x = read();
if(x == 5) cnt1 ++;
else if(x == 10) {
if(!cnt1) Flag = true;
else cnt1 --;
cnt2 ++;
} else if(x == 20) {
if(cnt2) {
cnt2 --;
if(cnt1) cnt1 --;
else Flag = true;
} else {
if(cnt1 < 3) Flag = true;
else cnt1 -= 3;
}
cnt3++;
}
}
if(Flag) puts("NO");
else puts("YES");
return 0;
}
T2 program
Solution
Greedy from the back to the front. Maintain a stack, If a location does not match the top of the stack or if the location is marked, So just push it(Let it as an open parenthesis), Otherwise it matches the top of the stack(Let it as a close parenthesis).
If there are elements in the stack at the end, That no solution,Otherwise, output the answer in positive order.
Code
/*
Work by: Suzt_ilymtics
Problem: program
Knowledge: Stack
Time: O(Can AC)
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define LL long long
#define orz cout<<"lkp AK IOI!"<<endl
using namespace std;
const int MAXN = 2e6+5;
const int INF = 1e9+7;
const int mod = 1e9+7;
int n, m;
int a[MAXN], b[MAXN];
int stc[MAXN], sc = 0;
bool Flag = false, ans[MAXN];
int read(){
int s = 0, f = 0;
char ch = getchar();
while(!isdigit(ch)) f |= (ch == '-'), ch = getchar();
while(isdigit(ch)) s = (s << 1) + (s << 3) + ch - '0' , ch = getchar();
return f ? -s : s;
}
int main()
{
// freopen("program.in","r",stdin);
// freopen("program.out","w",stdout);
n = read();
for(int i = 1; i <= n; ++i) a[i] = read();
m = read();
for(int i = 1, x; i <= m; ++i) b[read()] = 2;
for(int i = n; i >= 1; --i) {
if(b[i] == 2) {
ans[i] = 2, stc[++sc] = i;
} else {
if(sc && a[stc[sc]] == a[i]) sc--;
else stc[++sc] = i, ans[i] = 2;
}
}
if(sc) return puts("NO"), 0;
for(int i = 1; i <= n; ++i) {
if(ans[i]) {
printf("-%d ", a[i]);
} else {
printf("+%d ", a[i]);
}
}
puts("");
return 0;
}
T3 maze
Solution
In one sentence, The brackets match on the diagram.
Use \(dis_{i,j,w}\) to mark whether or not an edge appears, Remember to initialize \(dis_{i,j,0} = true\).
Consider how to merging two edges to form a new edge,
Let's say that the two sides are \((i,j,w)\) 和 \((j,k,c)\)
If \(w = 0\) or \(c = 0\), Then two edges can be merged.
If \(w = -c\), Then two edges can be merged.
The merged edge continues to queue for updates.
Code
/*
Work by: Suzt_ilymtics
Problem: maze
Knowledge: Graph
Time: O(Can AC)
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define LL long long
#define orz cout<<"lkp AK IOI!"<<endl
using namespace std;
const int MAXN = 1e5+5;
const int INF = 1e9+7;
const int mod = 1e9+7;
struct node { int u, v, w; };
int n, m, Q;
int dis[110][110][25];
queue<node> q;
int read(){
int s = 0, f = 0;
char ch = getchar();
while(!isdigit(ch)) f |= (ch == '-'), ch = getchar();
while(isdigit(ch)) s = (s << 1) + (s << 3) + ch - '0' , ch = getchar();
return f ? -s : s;
}
void bfs() {
while(!q.empty()) {
node U = q.front(); q.pop();
int u = U.u, v = U.v, w = U.w;
if(!w) {
for(int i = 1; i <= n; ++i) {
for(int k = 0; k <= 10; ++k) {
if(dis[i][u][k + 11] && !dis[i][v][k + 11]) dis[i][v][k + 11] = true, q.push((node){i, v, k});
if(dis[v][i][k + 11] && !dis[u][i][k + 11]) dis[u][i][k + 11] = true, q.push((node){u, i, k});
}
}
} else {
for(int i = 1; i <= n; ++i) {
if(dis[v][i][11 - w] && !dis[u][i][0 + 11]) dis[u][i][0 + 11] = true, q.push((node){u, i, 0});
}
}
}
}
int main()
{
n = read(), m = read();
for(int i = 1; i <= n; ++i) dis[i][i][11] = true;
for(int i = 1, u, v, w; i <= m; ++i) {
u = read(), v = read(), w = read();
if(!w) {
dis[u][v][11] = dis[v][u][11] = true;
q.push((node){u, v, 0}), q.push((node){v, u, 0});
} else if(w < 0) {
dis[u][v][w + 11] = dis[v][u][w + 11] = true;
} else {
dis[u][v][w + 11] = dis[v][u][w + 11] = true;
q.push((node){u, v, w}), q.push((node){v, u, w});
}
}
bfs();
Q = read();
for(int i = 1, u, v; i <= Q; ++i) {
u = read(), v = read();
if(dis[u][v][11]) puts("YES");
else puts("NO");
}
return 0;
}
标签:ch,solving,long,sc,report,problem,include,Problem,define 来源: https://www.cnblogs.com/Silymtics/p/test-GRYZ20211104.html