https://nanti.jisuanke.com/t/31458
#include <bits/stdc++.h>
using namespace std;
int n,k,x,y,res;
int read()
{
int f=1,x=0;
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;
}
void input()
{
map<int,map<int,int> > mp[2];
res=0;
n=read();
for(int i=1;i<=n;i++)
{
k=read();
if(k==0) mp[i&1].clear();
for(int j=1;j<=k;j++)
{
x=read(),y=read();
mp[i&1][x][y]=mp[(i+1)&1][x][y]+1;
res=max(res,mp[i&1][x][y]);
}
}
printf("%d\n",res);
}
int main()
{
int t;
t=read();
while(t--)
{
input();
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
map<int,map<int,int> > mp[100005];
int n,k,x,y,res;
int read()
{
int f=1,x=0;
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;
}
void input()
{
res=0;
n=read();
for(int i=1;i<=n;i++) mp[i].clear();
for(int i=1;i<=n;i++)
{
k=read();
for(int j=1;j<=k;j++)
{
x=read(),y=read();
mp[i][x][y]=mp[i-1][x][y]+1;
res=max(res,mp[i][x][y]);
}
}
printf("%d\n",res);
}
int main()
{
int t;
t=read();
while(t--)
{
input();
}
return 0;
}
滚动WA,不滚A
http://poj.org/problem?id=2431
#include <stdio.h>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
int res,nowl,nown,n,L,P;
struct cmp{
bool operator()(int a,int b)
{
return a<b;
}
};
struct node
{
int l,p;
}f[10005];
bool cmp1(node a,node b)
{
return a.l<b.l;
}
void read()
{
for(int i=0;i<n;i++)
{
scanf("%d%d",&f[i].l,&f[i].p);
}
scanf("%d%d",&L,&P);
}
void prework()
{
for(int i=0;i<n;i++) f[i].l=L-f[i].l;
sort(f,f+n,cmp1);
}
void init()
{
res=nown=0;
}
void work()
{
priority_queue <int,vector<int>,cmp> pq;
nowl=P;
while(1)
{
if(nowl>=L) break;
while(nown<n&&nowl>=f[nown].l)
{
pq.push(f[nown].p);
nown++;
}
if(pq.empty())
{
printf("-1\n");
return ;
}
nowl=nowl+pq.top();
pq.pop();
res++;
}
printf("%d\n",res);
return ;
}
int main()
{
while(cin>>n)
{
init();
read();
prework();
work();
}
return 0;
}
poj ac,但某平台RE
http://acm.hdu.edu.cn/showproblem.php?pid=1044
#include <bits/stdc++.h>
using namespace std;
int w,h,l,m,ct=1,control=0;
int dir[4][2]={{0,1},{0,-1},{-1,0},{1,0}};
int vis[55][55],path[20][20],pre[20],val[20],ans,cut;
string maze[55];
struct node
{
int x,y,step;
};
bool isvaild(int x,int y)
{
if(x<0||x==h||y<0||y==w||maze[x][y]=='*'||vis[x][y]) return false;
return true;
}
void init()
{
for(int i=0;i<20;i++)
{
for(int j=0;j<20;j++) path[i][j]=10000000;
}
memset(pre,0,sizeof(pre));
ans=-1;
cut=0;
}
void read()
{
cin>>w>>h>>l>>m;
for(int i=1;i<=m;i++) cin>>val[i],cut+=val[i];
for(int i=0;i<h;i++) cin>>maze[i];
}
void bfs(int x1,int y1,int from)
{
queue <node> q;
memset(vis,0,sizeof(vis));
vis[x1][y1]=1;
node a,b;
a.x=x1,a.y=y1,a.step=0;
q.push(a);
while(!q.empty())
{
b=q.front();
q.pop();
for(int i=0;i<4;i++)
{
a.x=b.x+dir[i][0];
a.y=b.y+dir[i][1];
a.step=b.step+1;
if(isvaild(a.x,a.y))
{
vis[a.x][a.y]=1;
q.push(a);
if(maze[a.x][a.y]=='<') path[from][m+1]=a.step;
if(maze[a.x][a.y]>='A'&&maze[a.x][a.y]<='J') path[from][maze[a.x][a.y]-'A'+1]=a.step;
}
}
}
}
void predfs()
{
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
if(maze[i][j]=='@') bfs(i,j,0);
// if(maze[i][j]=='<') bfs(i,j,m+1);
if(maze[i][j]>='A'&&maze[i][j]<='J') bfs(i,j,maze[i][j]-'A'+1);
}
}
}
void dfs(int now,int value,int TIME)
{
if(TIME>l||ans==cut) return ;
if(now==m+1)
{
ans=max(ans,value);
return ;
}
for(int i=1;i<=m+1;i++)
{
if(!pre[i])
{
pre[i]=1;
dfs(i,value+val[i],TIME+path[now][i]);
pre[i]=0;
}
}
return ;
}
void print()
{
printf("Case %d:\n",ct++);
if(ans!=-1) printf("The best score is %d.\n",ans);
else printf("Impossible\n");
}
int main()
{
int t;
cin>>t;
while(t--)
{
if(control) printf("\n");
control=1;
init();
read();
predfs();
dfs(0,0,0);
print();
}
return 0;
}
不知道WA的数据
http://hihocoder.com/problemset/problem/1828
/*
贪心法则:
1.B房间最多走5次
2.能走下一个点的条件为氧气管比之前都要多,或者说走的时间比之前少。
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=105;
struct node
{
int x,y,t,cnt,pcnt;
};
int n,m,res;
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
bool isvalid(int x,int y)
{
if(x<0||x==n||y<0||y==m) return false;
return true;
}
int have[N][N],used[N][N],tim[N][N];
node a,b;
string s[105];
queue <node> q;
void input()
{
for(int i=0;i<n;i++) cin>>s[i];
return ;
}
void pre()
{
while(!q.empty()) q.pop();
res=1e9;
memset(have,-1,sizeof(have));
memset(used,0,sizeof(used));
memset(tim,127,sizeof(tim));
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(s[i][j]=='S')
{
a.x=i,a.y=j,a.cnt=0,a.t=0,a.pcnt=0;
}
}
}
q.push(a);
return ;
}
void bfs()
{
while(!q.empty())
{
a=q.front();
q.pop();
if(s[a.x][a.y]=='T')
{
if(res>a.t) res=a.t;
}
else
{
for(int i=0;i<4;i++)
{
b.x=a.x+dir[i][0];
b.y=a.y+dir[i][1];
if(isvalid(b.x,b.y))
{
if(res>a.t)
{
if(s[b.x][b.y]=='B')
{
if(used[b.x][b.y]<5)
{
used[b.x][b.y]++;
b.cnt=a.cnt+1;
b.t=a.t+1;
if(a.pcnt>0)
{
b.pcnt=a.pcnt-1;
b.t--;
}
else b.pcnt=0;
tim[b.x][b.y]=min(tim[b.x][b.y],b.t);
q.push(b);
}
}
else
{
if(a.cnt>have[b.x][b.y]||a.t<tim[b.x][b.y])
{
if(s[b.x][b.y]=='P')
{
have[b.x][b.y]=a.cnt;
b.t=a.t+1;
if(a.pcnt>0)
{
b.pcnt=a.pcnt;
b.t--;
}
else b.pcnt=1;
tim[b.x][b.y]=min(tim[b.x][b.y],b.t);
b.cnt=a.cnt;
q.push(b);
}
else if(s[b.x][b.y]=='#')
{
if(a.cnt>0)
{
have[b.x][b.y]=a.cnt;
b.t=a.t+2;
if(a.pcnt>0)
{
b.pcnt=a.pcnt-1;
b.t--;
}
else b.pcnt=0;
tim[b.x][b.y]=min(tim[b.x][b.y],b.t);
b.cnt=a.cnt-1;
q.push(b);
}
}
else
{
have[b.x][b.y]=a.cnt;
b.t=a.t+1;
if(a.pcnt>0)
{
b.pcnt=a.pcnt-1;
b.t--;
}
else b.pcnt=0;
tim[b.x][b.y]=min(tim[b.x][b.y],b.t);
b.cnt=a.cnt;
q.push(b);
}
}
}
}
}
}
}
}
if(res==1e9) printf("-1\n");
else printf("%d\n",res);
}
int main(int argc, char *argv[])
{
while(cin>>n>>m,n||m)
{
input();
pre();
bfs();
}
return 0;
}
不知道哪WA