纪中游记(四)

20190805

写在前面的话

今天的题竟然全是模拟!!!

太有趣了。

T0

哇,这一题是真的简单。

如果是管道,只需要处理周围与它联通的方格,例如

 1             //莫名其妙的空行 2             if(ch=='|')
 3                 op[i-1][j]+=200,op[i+1][j]+=1000;
 4             else if(ch=='-')
 5                 op[i][j-1]+=4,op[i][j+1]+=30;
 6             else if(ch=='+')
 7                 op[i-1][j]+=200,op[i+1][j]+=1000,op[i][j-1]+=4,op[i][j+1]+=30;
 8             else if(ch=='1'||ch=='2'||ch=='3'||ch=='4')
 9             {
10                 if(ch-'0'==1) op[i][j+1]+=30,op[i+1][j]+=1000;
11                 else if(ch-'0'==2) op[i-1][j]+=200,op[i][j+1]+=30;
12                 else if(ch-'0'==3) op[i][j-1]+=4,op[i-1][j]+=200;
13                 else if(ch-'0'==4) op[i][j-1]+=4,op[i+1][j]+=1000;
14             }
15             else if(ch=='M')
16                 op[i-1][j]+=200,op[i+1][j]+=1000,op[i][j-1]+=4,op[i][j+1]+=30;
17             else if(ch=='Z')
18                 op[i-1][j]+=200,op[i+1][j]+=1000,op[i][j-1]+=4,op[i][j+1]+=30;

之后再打一个循环找到遗失的管道就行了

 1             if(op[i][j]==1200)
 2             {
 3                 cout<<i<<" "<<j<<" "<<'|';
 4                 return 0;
 5             }
 6             else if(op[i][j]==34)
 7             {
 8                 cout<<i<<" "<<j<<" "<<'-';
 9                 return 0;
10             }
11             else if(op[i][j]==1234)
12             {
13                 cout<<i<<" "<<j<<" "<<'+';
14                 return 0;
15             }
16             else if(op[i][j]==1030)
17             {
18                 cout<<i<<" "<<j<<" "<<'3';
19                 return 0; 
20             }
21             else if(op[i][j]==230)
22             {
23                 cout<<i<<" "<<j<<" "<<'4';
24                 return 0;
25             }
26             else if(op[i][j]==204)
27             {
28                 cout<<i<<" "<<j<<" "<<'1';
29                 return 0;
30             }
31             else if(op[i][j]==1004)
32             {
33                 cout<<i<<" "<<j<<" "<<'2';
34                 return 0;
35             }
36             else continue;

毫无悬念的AC。(第一次写‘复’这么水)

细心就可以。

T1

当初看这题的时候,就直接跳过了。

土法

完全模拟,结果时间爆炸

正解

只用关注移动的点,然后再模拟

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int r,c,op[30][30];
 4 int main()
 5 {
 6     scanf("%d%d",&r,&c);
 7     for(register int i=1;i<=r;i++)
 8     {
 9         for(register int j=1;j<=c;j++)
10         {
11             char ch;
12             cin>>ch;
13             if(ch=='.');
14             else
15             {
16             op[i][j]+=10000;    
17             if(ch=='|')
18                 op[i-1][j]+=200,op[i+1][j]+=1000;
19             else if(ch=='-')
20                 op[i][j-1]+=4,op[i][j+1]+=30;
21             else if(ch=='+')
22                 op[i-1][j]+=200,op[i+1][j]+=1000,op[i][j-1]+=4,op[i][j+1]+=30;
23             else if(ch=='1'||ch=='2'||ch=='3'||ch=='4')
24             {
25                 if(ch-'0'==1) op[i][j+1]+=30,op[i+1][j]+=1000;
26                 else if(ch-'0'==2) op[i-1][j]+=200,op[i][j+1]+=30;
27                 else if(ch-'0'==3) op[i][j-1]+=4,op[i-1][j]+=200;
28                 else if(ch-'0'==4) op[i][j-1]+=4,op[i+1][j]+=1000;
29             }
30             else if(ch=='M')
31                 op[i-1][j]+=200,op[i+1][j]+=1000,op[i][j-1]+=4,op[i][j+1]+=30;
32             else if(ch=='Z')
33                 op[i-1][j]+=200,op[i+1][j]+=1000,op[i][j-1]+=4,op[i][j+1]+=30;
34             }
35         }
36     }
37     for(register int i=1;i<=r;i++)
38     {
39         for(register int j=1;j<=c;j++)
40         {
41             if(op[i][j]>=10000)
42                 continue;
43             if(op[i][j]==1200)
44             {
45                 cout<<i<<" "<<j<<" "<<'|';
46                 return 0;
47             }
48             else if(op[i][j]==34)
49             {
50                 cout<<i<<" "<<j<<" "<<'-';
51                 return 0;
52             }
53             else if(op[i][j]==1234)
54             {
55                 cout<<i<<" "<<j<<" "<<'+';
56                 return 0;
57             }
58             else if(op[i][j]==1030)
59             {
60                 cout<<i<<" "<<j<<" "<<'3';
61                 return 0; 
62             }
63             else if(op[i][j]==230)
64             {
65                 cout<<i<<" "<<j<<" "<<'4';
66                 return 0;
67             }
68             else if(op[i][j]==204)
69             {
70                 cout<<i<<" "<<j<<" "<<'1';
71                 return 0;
72             }
73             else if(op[i][j]==1004)
74             {
75                 cout<<i<<" "<<j<<" "<<'2';
76                 return 0;
77             }
78             else continue;
79         }
80     }
81 }
无聊的代码

我竟然直接放弃了,亏

T2

完全暴力模拟水了50分。开心

 

T3

直接模拟,结果才7.7分,what?

正解听说是一个叫差分树状数组的东西,实际上在进阶指南上就有,十分清晰易懂

其实只用差分的原理就可以实现区间修改。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 inline int read()
 4 {
 5     int x=0;
 6     char ch=getchar();
 7     while(ch<'0'||ch>'9')
 8     {
 9         ch=getchar();
10     }
11     while(ch>='0'&&ch<='9')
12     {
13         x=(x<<1)+(x<<3)+ch-'0';
14         ch=getchar();
15     }
16     return x;
17 }
18 struct jkl
19 {
20     int x,y;
21 }op[100005];
22 int n,m,a[100005],re[100005];
23 void add(int xx,int yy)
24 {
25     while(xx<=m)
26     {
27         a[xx]++;
28         xx+=((xx)&(-xx));
29     }
30     while(yy<=m)
31     {
32         a[yy]--;
33         yy+=((yy)&(-yy));
34     }
35 }
36 inline int ask(int xx)
37 {
38     int num=0;
39     while(xx)
40     {
41         num+=a[xx];
42         xx-=((xx)&(-xx));
43     }
44     return num;
45 }
46 int main()
47 {
48     n=read();
49     for(register int i=1;i<=n;i++)
50     {
51         int l,r;
52         l=read(),r=read();
53         op[i].x=l,op[i].y=r;
54         m=max(m,r);
55     }
56     for(register int i=1;i<=n;i++)
57     {
58         int anl=ask(op[i].x),anr=ask(op[i].y);
59         printf("%d\n",anr+anl-re[op[i].x]-re[op[i].y]);
60         re[op[i].x]=max(re[op[i].x],anl);
61         re[op[i].y]=max(re[op[i].y],anr);
62         add(op[i].x+1,op[i].y);
63     }
64     return 0;
65 }
说是裸树状数组你信么

转化很重要!

 

posted @ 2019-08-06 21:49  HHHG  阅读(162)  评论(0编辑  收藏  举报