• 11.4 problem solving report of Simulation Competition


    Background:

    Hearing Szt && BS' English is poor last night.

    So I try writting this in English this time. /xyx

    Examination process:

    7:30 hand out test questions

    7:45 Finish T1

    8:20 Finish T2

    8:30 ~ 9:00 Begin to do T3

    9:30 Be sure I can't finish T3

    9:00 ~ 11:00 Play very happily /cy

    Dream: pts:100 + 100 + 0 = 200

    True: pts: 100 + 40 + 0 = 40

    ahh Why My T2 Hang up ??

    T1 buy book

    solution

    Easy problem!!

    Simulated topic meaning.

    Only notice: When you encounter 20, first consider using 10.

    Time: (O(n))

    code

    #include<bits/stdc++.h>
    using namespace std;
    int read() {
      int x = 0, f = 1; char c = getchar();
      while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
      while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = getchar();}
      return x * f;
    }
    int n, cnt[5];
    int main() {
      //freopen("book.in", "r", stdin);
      //freopen("book.out", "w", stdout);
      n = read();
      for (int i = 1; i <= n; i++) {
      	int x = read();
      	if(i == 1 && x > 5) {puts("NO"); return 0;}
      	if(x == 5) cnt[1]++;	 
    	else if(x == 10) {
    	  if(!cnt[1]) {puts("NO"); return 0;}
    	  cnt[1]--, cnt[2]++;
    	}
        else if(x == 20) {
          if(!cnt[1]) {puts("NO"); return 0;}
          cnt[1]--;
          if(cnt[2]) cnt[2]--, cnt[3]++;
    	  else {
    	  	if(cnt[1] < 2) {puts("NO"); return 0;}
    	  	cnt[1] -= 2, cnt[3]++;
    	  }
        }
      }
      puts("YES");
      return 0;
    }
    
    

    T2 program

    solution

    Using a stack to do this from tail to head.

    This problem will become very easy !!

    I didn't take care of the details, So I hang up 60pts

    Time: (O(n))

    code

    #include<bits/stdc++.h>
    using namespace std;
    const int MAXN = 1e6 + 5;
    int read() {
      int x = 0, f = 1; char c = getchar();
      while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
      while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = getchar();}
      return x * f;
    }
    int n, m, st[MAXN], a[MAXN], tp, pos[MAXN];
    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++) {
        x = read(); 
        if(a[x] > 0) a[x] = -a[x];  	
      }
      st[++tp] = a[n], pos[tp] = n;
      for (int i = n - 1; i >= 1; i--) {
      	 if(a[i] < 0) st[++tp] = a[i], pos[tp] = i;
      	 else {
      	   if(abs(st[tp]) == a[i]) {
    		  if(a[pos[tp]] > 0) a[pos[tp]] = -a[pos[tp]]; 
    		  tp--;
    		}
    	   else st[++tp] = a[i], pos[tp] = i;
    	 }
      }
      if(tp) puts("NO");
      else {
      	for (int i = 1; i <= n; i++) {
      	  if(a[i] > 0) printf("+%d ", a[i]);
    	  else printf("%d ", a[i]);	
    	}
      }
      return 0;
    }
    
    

    T3 maze

    solution

    Bracket match on figure

    code

    #include<bits/stdc++.h>
    using namespace std;
    const int MAXN = 110;
    const int MAXM = 50010;
    int read() {
      int x = 0, f = 1; char c = getchar();
      while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
      while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = getchar();}
      return x * f;
    }
    int n, m, T;
    struct node{int u, v, w;};
    queue<node> q;
    bool f[110][110][21];
    void Init() {
       for (int i = 1, u, v, w; i <= m; i++) {
      	u = read(), v = read(), w = read();
      	if(!w) {
      	  f[u][v][w] = f[v][u][w] = true;
      	  q.push((node){u, v, w}), q.push((node){v, u, w});
    	}
    	else if (w < 0) {
    	  w = -w;
    	  f[u][v][w] = f[v][u][w] = true; 
    	}
    	else {
    	   w += 10;
    	   f[u][v][w] = f[v][u][w] = true;
    	   q.push((node){u, v, w}), q.push((node){v, u, w});
    	}
      }
    }
    void Update() {
      while(!q.empty()) {
      	 int u = q.front().u, v = q.front().v, w = q.front().w;
      	 q.pop();
    	 if(!w) {
      	  for (int i = 1; i <= n; i++) {
      	     if (f[i][u][0] && !f[i][v][0]) {
      	        f[i][v][0] = 1;
    			q.push((node){i, v, 0});	 
    		  }
    		  if(f[v][i][0] && !f[u][i][0]) {
    		  	 f[u][i][0] = 1;
    		  	 q.push((node){u, i, 0});
    		  }	
    		  for (int j = 11; j <= 20; j++) {
    		  	 if (f[i][u][j] && !f[i][v][j]) {
    		  	   f[i][v][j] = 1;
    			   q.push((node){i, v, j});	 
    			 }
    		  }
    	   }	
    	 }
    	 else {
    	    for (int i = 1; i <= n; i++) {
    	      if(f[v][i][w - 10] && !f[u][i][0]) {
    	      	f[u][i][0] = 1;
    	      	q.push((node){u, i, 0});
    		  }
    		}
    	 }
      }
    }
    int main() {
      n = read(), m = read();
      for (int i = 1; i <= n; i++) f[i][i][0] = 1;
      Init();
      Update();
      T = read();
      for (int i = 1, u, v; i <= T; i++){
        u = read(), v = read();
        puts(f[u][v][0] ? "YES" : "NO");
      }
      return 0;
    }
    
  • 相关阅读:
    java环境配置
    关于Chrome(谷歌浏览器)对docume,准确获取网页客户区的宽高、滚动条宽高、滚动条Left和Top
    CSS3圆角详解
    Js监控回车事件
    Sql日期时间格式转换
    JS操作JSON总结
    SQL日期操作及只获取日期的方法
    如何让div出现滚动条
    CodeForces 55D Beautiful numbers
    POJ 3034 Whac-a-Mole
  • 原文地址:https://www.cnblogs.com/Arielzz/p/15508205.html
Copyright © 2020-2023  润新知