1 solutions
-
0
C++ :
#include <cstdio> using namespace std; const int N(103); struct point { int r,c; }; point cow[N]; bool East[N]={false},North[N]={false},Removed[N]={false}; int r,c,n; bool safe() { for(int i=1;i<=n;i++) if(!Removed[i]) { East[i]=false; North[i]=false; for(int j=1;j<=n;j++) if(j!=i&&(!Removed[j])) { if(cow[j].c>cow[i].c&&cow[j].r==cow[i].r) East[i]=true; if(cow[j].r<cow[i].r&&cow[j].c==cow[i].c) North[i]=true; } if(East[i]&&North[i]) return false; } return true; } int main() { scanf("%d%d%d",&r,&c,&n); for(int i=1;i<=n;i++) scanf("%d%d",&cow[i].r,&cow[i].c); if(safe()) { printf("0\n"); return 0; } else for(int i=1;i<=n;i++) { Removed[i]=true; if(safe()) { printf("1\n%d\n",i); return 0; } else Removed[i]=false; } printf("-1\n"); return 0; }
- 1
Information
- ID
- 663
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By