ZJNU 2206 - 染色

开纵横两个结构体数组,记录连续涂了一整行或者一整列的情况

再开一个map,记录涂点

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<map>
 4 #include<utility>
 5 using namespace std;
 6 typedef pair<int,int> P;
 7 struct node{
 8     int color,time;
 9 }x[2010],y[2010];
10 map<P,node> mp;
11 int main(){
12     ios::sync_with_stdio(0);
13     cin.tie(0);cout.tie(0);
14     int T,n,m,q,i,tm,kd,a,b,cl,d1,d2,d3;
15     node dd;
16     cin>>T;
17     while(T--){
18         cin>>n>>m>>q;
19         mp.erase(mp.begin(),mp.end());
20         for(i=1;i<=n;i++){
21             x[i].color=-1;
22             x[i].time=0;
23         }
24         for(i=1;i<=m;i++){
25             y[i].color=-1;
26             y[i].time=0;
27         }
28         tm=1;
29         for(i=0;i<q;i++){
30             cin>>kd;
31             if(kd==1){
32                 cin>>a>>cl;
33                 x[a].color=cl;
34                 x[a].time=tm++;
35             }
36             else if(kd==2){
37                 cin>>b>>cl;
38                 y[b].color=cl;
39                 y[b].time=tm++;
40             }
41             else if(kd==3){
42                 cin>>a>>b>>cl;
43                 dd.color=cl;
44                 dd.time=tm++;
45                 mp[P(a,b)]=dd;
46             }
47             else{
48                 cin>>a>>b;
49                 d1=x[a].time;
50                 d2=y[b].time;
51                 d3=-1;
52                 if(mp.find(P(a,b))!=mp.end())
53                     d3=mp[P(a,b)].time;
54                 if(d1>d2&&d1>d3)
55                     cout<<x[a].color<<endl;
56                 else if(d2>d1&&d2>d3)
57                     cout<<y[b].color<<endl;
58                 else
59                     cout<<mp[P(a,b)].color<<endl;
60             }
61         }
62     }
63     
64     return 0;
65 }

猜你喜欢

转载自www.cnblogs.com/stelayuri/p/12236621.html