Summary of the 9th Blue Bridge Cup C/C++ Group B National Competition in 2018

On April 1, 2018, in the provincial competition of the Blue Bridge Cup, when the results were only correct for two, relying on the big question, I accidentally entered the national competition. I was a little surprised. After all, it was my first time participating in the blue Bridge Cup. It is also worthy of being so serious about a month before the provincial competition. In the national competition on May 26, during the preparation time for more than a month, I also put down the python and web pages that I planned to study hard, and continued to mess around in the sea of ​​c/c++ questions.

I took a 5-day leave, took the train at 2:30 p.m. on May 24, took 20 hours, and arrived in Beijing on the 25th. On the afternoon of the 25th, I went to the Capital University of Economics and Business to look at the examination room. Then, because it was too late, I had to go to Nanluoguxiang and Houhai with my classmates. (ps: I had a good lunch at noon. The Beijing classic roast duck is really expensive for half a piece of 78 yuan, and I really can’t get used to it and enjoy the delicious taste in the eyes of northerners). On the morning of the 26th, I did a good review and did not go out to play all morning. For lunch, I just ate some snacks in the hotel and made do with it. Then I went to the exam room a little later.

The examination room will distribute paper and pens (pens are commemorative pens for the finals and can be taken away), a bottle of water, a box of milk, and a piece of bread. I thought about it and wanted to do more to win the prize, so I didn't have time to drink milk and eat bread. Seeing the title, the first question is very simple, and the two-layer for loop can be solved directly. The second question, for 30 lights on and off the lights, didn’t think much about whether there was a simpler way, anyway, it was a result question, so I wrote 30 layers of for loops in a very Buddhist way, and each layer of for traverses 0 and 1 Analog switch lights. The third question is the code fill-in-the-blank question to get Gray code by bit operation. After reading the first big question, I felt like I had to skip it after a while. The second big question felt quite difficult and I skipped it. I was very happy when I saw the third big question. Write violent code, try to break through a better method, and fail to come up with it. I went back and did the first big question. After thinking about it for a while, it was a simulation. The code is as follows:

#include<stdio.h>
#include<string.h>
#include<set>
using namespace std;
int main() {
  int n, k, i, sum = 1, a[100005], t;
  memset(a, 0, sizeof(a));
  a[0] = 1;//起点 
  scanf("%d%d", &n, &k);
  for(i = 1; i <= n; i++) {
    set<int> s;
    for(int j = 0; j < n; j++) {
      if(a[j]) {
        t = j + 1;
        if(t >= n) t = (t - n) % n;
        if(!a[t]) s.insert(t);
        t = j + k;
        if(t >= n) t = (t - n) % n;
        if(!a[t]) s.insert(t);
      }
    }
    sum += s.size();
    set<int>::iterator iter;
    for(iter = s.begin(); iter != s.end(); iter++)
      a[*iter] = 1;
    if(sum >= n) break;
  }
  printf("%d\n", i);
  return 0;
}

Then I worked hard on the second big question. After thinking about it for a long time, I couldn't think of a good way, so I wrote a simulation method to get some points. I wrote and modified it. When there was only more than half an hour left, I went back and checked the topics I did earlier. I focused on my 30-layer for loop. I really saw that there was a variable repeated, in time Changed it back, and it did not lead to loss of points for simple questions. In the last 5 minutes, I finally finished the simulation of the second big question. I felt that I could get some points for some data, and I was very happy. I recalled it from memory, and vaguely remembered that it was written like this:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n, m;
char Map[1005][1005], s[1005][1005];
int a[1005];
struct point {
  int x, y;
}p[1000005]; 
int check() {
  for(int i = 1; i <= n; i++) {
    int t = 0, p;
    for(int j = 1; j <= m; j++) 
      if(s[i][j] == 'o') {
        if(s[i+1][j] == '.') return 0;
        p = j;
        t++;
      }
    if(t > 1) {
      for(int j = t; j >= 0; j--)
        if(s[i][j-1] != 'o') return 0;
    }
  }
  return 1;
}
int main() {
  memset(p, 0, sizeof(p));
  long long sum = 1, tot = 0;
  scanf("%d%d", &n, &m);
  for(int i = 1; i <= n; i++) {
    getchar();
    for(int j = 1; j <= m; j++)
      scanf("%c", &Map[i][j]);
  }
  for(int i = 1; i <= n; i++) 
    for(int j = 1; j <= m; j++)
      if(Map[i][j] == '.' && Map[i+1][j] != '*') {
        p[tot].x = i;
        p[tot].y = j;
        tot++; 
      }
  for(int i = 1; i <= tot; i++) {//摆放多少个点 
    memset(a, 0, sizeof(a));
    for(int j = tot-1; j >= tot-i; j--) 
      a[j] = 1;
    do {
      for(int ii = 1; ii <= n; ii++) 
        for(int jj = 1; jj <= m; jj++)
          s[ii][jj] = Map[ii][jj];
      for(int ii = 0; ii < tot; ii++)
        if(a[ii]) s[p[ii].x][p[ii].y] = 'o';
      if(check()) sum++;
    }while(next_permutation(a, a+tot));
  }
  printf("%lld\n", sum);
  return 0;
}

That's about it, I did 5 questions, and it should look like 4 in total.

After the exam, I went to my cousin to play, and went to the Bird's Nest and the Water Cube. I also bought a ticket of 180 per person to watch the light show and Peking Opera in the Bird's Nest. The light show is the light of the Bird's Nest playing on the track and field. I feel it is normal, and the sound is very good. Peking Opera is a sucker. My VIP ticket was sitting at the square table in the front row. It turned out that one or two people sang duet to the animators on the screen. There were no real people playing drums. The soundtrack was entirely based on animation. After watching it for ten minutes, I couldn't starve, and I couldn't stand it any longer, so I went out. There are very few places to eat on the edge of the bird's nest, and it is very expensive. A small bowl of hot and sour noodles is 26 yuan, and a meat bun is 16 yuan. The taste is also average. On the 27th, I first went to see the Sigma Building, then went to Beihang University to see the Aerospace and Aviation Museum inside. He went to Tsinghua University instead, ran two doors and refused to let him in, he had to go to the south gate to let him in. In the middle of this, the results also came out. The second prize was also quite unexpected. I was quite satisfied. It really was the Violence Cup. After a good lunch, my classmates said they didn’t want to go to Tsinghua University, so they went to Peking University. Dramatically, I got in with Peking University students, and my classmates were stopped. So my mother divided the army into two groups. I was shopping in Peking University, and he went to the National Library. After that, I went to the Summer Palace, but I asked for a ticket. I made a miscalculation, so I didn't go in and went directly to Tiananmen Square. After visiting Tiananmen Square, go back to the hotel, and then go to Beijing West Railway Station to take the train.

I arrived in Nanchang at 7:30 in the morning on the 28th. The classmates and the leading teacher went back to Yichun first. I stayed in Nanchang alone to watch pigs eat pigs, hahahahahaha. I also rode the Ferris wheel at night. The Nanchang Star Ferris Wheel is really beautiful and high, but the rotation speed is too slow. It took half an hour to make a circle. Scared to move hahaha. Then I bought the high-speed rail at 9:25 in the evening, and when I took the bus to Nanchang West Station, I ran wild and almost missed it. When I arrived at the school dormitory at 11:00, the 5-day vacation was over.

Publishing this article is only for summarizing memories. If a big guy passes by, I am a chicken. Please bear with me and don’t spray.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326568046&siteId=291194637