标签:
题目链接:
模拟题一道,比较水,但是因为题意曲折
顺带vector的删除操作也是不太明白
总之逗了很长时间
删除第i个元素
v.erase(v.begin() + i);
删完后后面的元素都会往前移一个,所以下一个元素还是v[i]
也可以下面这样
it = v.erase(it); //erase()返回值是指向下一个元素的指针
//#define __LOCAL //#define __LLD #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <time.h> #include <algorithm> #include <queue> #include <vector> #include <stack> #include <set> #include <map> #include <iostream> using namespace std; typedef long long LL; typedef pair<int,int> PII; const int ninf = 0x80000000; const int inf = 0x7FFFFFFF; const LL INF = (LL)inf*inf; #ifdef __LLD #define printLLln(x) printf("%lld\n", x) #define printLL(x) printf("%lld", x) #else #define printLLln(x) printf("%I64d\n", x) #define printLL(x) printf("%I64d", x) #endif #define MP make_pair #define PB push_back // struct LI { int x,y; int dx,dy; LI(){} LI(int _x,int _y,int _dx, int _dy) :x(_x),y(_y),dx(_dx),dy(_dy){} }; const int MAXN = 102; int n,r,c,T; vector<LI> w; int m[MAXN][MAXN]; int mm[MAXN][MAXN]; vector<PII> mmm; int res[MAXN]; void init() { memset(m,0,sizeof m); w.clear(); memset(mm, 0, sizeof(mm)); mmm.clear(); memset(res,-1,sizeof(res)); } void solve() { init(); int x,y,s; mmm.PB(MP(0,0)); for(int i=1;i<=n;++i) { scanf("%d%d%d", &x,&y,&s); m[x][y] = s; mm[x][y] = i; mmm.PB(MP(x,y)); } scanf("%d%d", &x,&y); w.push_back(LI(x,y,1,0)); w.push_back(LI(x,y,-1,0)); w.push_back(LI(x,y,0,1)); w.push_back(LI(x,y,0,-1)); bool dis; for(int i=1;i<=T;++i) { for(int j = 0; j < w.size();) { dis = false; // printf("%d %d %d %d\n", w[j].x, w[j].y, w[j].dx, w[j].dy); w[j].x += w[j].dx; w[j].y += w[j].dy; if(w[j].x > r || w[j].x < 1 || w[j].y > c || w[j].y < 1) dis = true; else if(m[w[j].x][w[j].y] > 0){ m[w[j].x][w[j].y] += 1; dis = true; } if(dis){ w.erase(w.begin()+j); } else ++j; } for(int j=1;j<=n;++j) { int xx = mmm[j].first; int yy = mmm[j].second; if(m[xx][yy] > 4){ m[xx][yy] = 0; res[mm[xx][yy]] = i; w.push_back(LI(xx,yy,1,0)); w.push_back(LI(xx,yy,-1,0)); w.push_back(LI(xx,yy,0,1)); w.push_back(LI(xx,yy,0,-1)); } } } for(int i=1;i<=n;++i) { if(res[i]!=-1){ printf("0 %d\n",res[i]); } else{ printf("1 %d\n",m[mmm[i].first][mmm[i].second]); } } } int main() { #ifdef __LOCAL freopen("/Users/apple/Documents/xcode/contest/data.in", "r", stdin); // freopen("/Users/apple/Documents/xcode/contest/data.out", "w", stdout); #endif // int T; //// int num=0; // scanf("%d",&T); // while(T--){ //// printf("Case #%d: ",++num); // solve(); // } // while(scanf("%d%d%d%d", &r,&c,&n,&T)!=EOF){ solve(); } return 0; }
hdu5336 XYZ and Drops (模拟+vector删除第i个元素)
标签:
原文地址:http://www.cnblogs.com/heiqi2piao/p/4691021.html