模拟赛#2

这场只肝出1题...

A.HDU 1231最大连续子序列

签到题。。

B.HDU 1176免费馅饼

比赛事没看这题全跑去干C了。。

f[i][j]表示第i个时刻第j个位置的最大数量,倒着枚举时间,考虑上一个时刻i+1相邻位置跑到j,需要注意的是可以原地不动.f[i][j]=max(max(f[i+1][j-1],f[i+1][j+1]),f[i+1][j])

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cmath>
 5 #include <cstring>
 6 #include <queue>
 7 #include <map>
 8 #define ll unsigned long long
 9 #define out(a) printf("%d",a)
10 #define writeln printf("\n")
11 const int N=1e5+50;
12 using namespace std;
13 int n,x,t;
14 int ans,maxn;
15 int num[N][12];
16 int f[N][12];
17 int read()
18 {
19     int s=0,t=1; char c;
20     while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
21     while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
22     return s*t;
23 }
24 ll readl()
25 {
26     ll s=0,t=1; char c;
27     while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
28     while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
29     return s*t;
30 }
31 int main()
32 {
33    while (~scanf("%d",&n)){
34        if (n==0) break;
35     maxn=-23333333;
36     memset(f,0,sizeof(f));
37     for (int i=1;i<=n;i++)
38       x=read(),t=read(),f[t][x]++,maxn=max(maxn,t);
39     for (int i=maxn-1;i>=0;i--)
40       for (int j=0;j<=10;j++)
41         f[i][j]+=max(max(f[i+1][j],f[i+1][j-1]),f[i+1][j+1]);
42     out(f[0][5]); writeln;
43   }
44     return 0;
45 }
View Code

C.HDU 1180诡异的楼梯

这恶心的宽搜我调了1天,最后还是有锅没AC,代码先放这里吧。。

  1 #include <iostream>
  2 #include <cstdio>
  3 #include <algorithm>
  4 #include <cmath>
  5 #include <cstring>
  6 #include <queue>
  7 #include <map>
  8 #define ll long long
  9 #define out(a) printf("%d ",a)
 10 #define writeln printf("\n")
 11 const int N=1e5+50;
 12 using namespace std;
 13 int n,m,fx,fy,lx,ly,ans;
 14 int maps[22][22],cnt[22][22];
 15 int dx[4]={1,-1,0,0};
 16 int dy[4]={0,0,1,-1};
 17 bool vis[22][22];
 18 char ch[22][22];
 19 struct node
 20 {
 21     int x,y,step;
 22     bool operator <(const node &a)const{
 23       return step>a.step;
 24     }
 25 };
 26 int read()
 27 {
 28     int s=0,t=1; char c;
 29     while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
 30     while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
 31     return s*t;
 32 }
 33 ll readl()
 34 {
 35     ll s=0,t=1; char c;
 36     while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
 37     while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
 38     return s*t;
 39 }
 40 bool check(int x,int y,int c)
 41 {
 42     if (x<=0||x>n||y<=0||y>m||vis[x][y]) return false;
 43     return true;
 44 }
 45 bool judge1(int a,int b,int c,int x)
 46 {
 47         if ((a%2==0&&maps[b][c]==1)||(a%2==1&&maps[b][c]==2)){
 48           if (x!=0) return true;
 49         }
 50     return false;
 51 }
 52 bool judge2(int a,int b,int c,int x)
 53 {
 54         if ((a%2==1&&maps[b][c]==1)||(a%2==0&&maps[b][c]==2)){
 55           if (x!=0) return true;
 56         }
 57     return false;
 58 }
 59 void bfs(int x,int y)
 60 {
 61     int numx,numy;
 62        priority_queue<node>q;
 63     node p,h;
 64     p.x=x; p.y=y; p.step=0;
 65     q.push(p);
 66     vis[x][y]=true; cnt[x][y]=1;
 67     while (!q.empty()){
 68         p=q.top();
 69         //out(p.x),out(p.y),out(p.step),writeln;
 70       for (int i=0;i<4;i++){
 71       h.x=p.x+dx[i]; h.y=p.y+dy[i];
 72         numx=numy=0;
 73         if (dx[i]!=0) numx=dx[i];
 74         if (dy[i]!=0) numy=dy[i];
 75         if (check(h.x,h.y,h.step)){
 76           if (maps[h.x][h.y]>0){
 77               if (judge1(p.step,h.x,h.y,numx)) {
 78                   h.x+=dx[i]; 
 79                   if (check(h.x,h.y,h.step)) { 
 80                       h.step=p.step+1;
 81                     if (h.x==lx&&h.y==ly) {
 82                      out(h.step); return;
 83                   }
 84                     vis[h.x-dx[i]][h.y]=true;
 85                     q.push(h);
 86                   }
 87             }
 88                 else if (judge2(p.step,h.x,h.y,numy)) {
 89                 h.y+=dy[i]; //out(h.x),out(h.y),out(h.step);
 90                 if (check(h.x,h.y,h.step)) { 
 91                    h.step=p.step+1;
 92                    //out(h.x),out(h.y),out(h.step); out(233);
 93                   if (h.x==lx&&h.y==ly) {
 94                    out(h.step); return;
 95                   }
 96                   vis[h.x][h.y-dy[i]]=true;
 97                    q.push(h);
 98                 }
 99             }
100                else if (judge2(p.step,h.x,h.y,numx)) {
101                   h.x+=dx[i];
102                   if (check(h.x,h.y,h.step)) q.push((node){p.x,p.y,p.step+1});
103             }
104               else if (judge1(p.step,h.x,h.y,numy)) {
105                   h.y+=dy[i]; //out(233);
106                   if (check(h.x,h.y,h.step)) q.push((node){p.x,p.y,p.step+1});
107                 }
108         }
109         else {
110           h.step=p.step+1;
111           if (h.x==lx&&h.y==ly) {
112            out(h.step); return;
113           }
114           vis[h.x][h.y]=true;
115           q.push(h);
116         }
117       }
118       cnt[h.x][h.y]=h.step;
119     }
120     q.pop();
121     }
122 }
123 int main()
124 {
125     while (~scanf("%d%d",&n,&m)){
126       memset(vis,0,sizeof(vis));
127       memset(maps,0,sizeof(maps));
128       ans=0;
129       for (int i=1;i<=n;i++)
130         for (int j=1;j<=m;j++){
131             cin>>ch[i][j];
132             if (ch[i][j]=='S') fx=i,fy=j;
133             if (ch[i][j]=='T') lx=i,ly=j;
134             if (ch[i][j]=='|') maps[i][j]=1;
135             if (ch[i][j]=='-') maps[i][j]=2;
136             if (ch[i][j]=='*') vis[i][j]=true;
137       }
138       bfs(fx,fy);
139       writeln;
140     }
141     return 0;
142 //5 5
143 //T..|.
144 //....|
145 //.-.-.
146 //....-
147 //..|.S
148 }
View Code

 

posted @ 2018-08-03 15:57  Kaleidoscope233  阅读(105)  评论(0编辑  收藏  举报