标签:des style blog http color io os ar strong
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 3081 | Accepted: 1398 |
Description
Input
Output
Sample Input
2 8 5 11 0 0 1 0 2 0 5 0 7 0 1 1 2 1 5 1 3 3 5 2 4 4 0 4 0 3 0 2 1 1 1 4 1 3 3 3 5 2 6 2 7 2 7 4 8 5 11 0 0 1 0 2 0 5 0 7 0 1 1 2 1 5 1 3 3 6 1 4 4 0 4 0 3 0 2 1 1 1 4 1 3 3 3 5 2 6 2 7 2 7 4
Sample Output
YES NO
问的是点阵图的同构。
应该有比较科学的方法的,但是我看到网上有一个做法是统计十字走的步数的方法。觉得非常神奇。虽然看起来不怎么科学,但是可能是数据比较水,居然能A。大致思路就是统计每个点能向四个方向走的步数的和,再比较这两个图中每个点是否都能找到一个总步数相同的点与之匹配
#include <iostream> #include <string.h> #include <stdio.h> #include <algorithm> using namespace std; struct node { int x; int y; } p[10005]; int map[105][105],n,w,h; int sum[2][10000]; int main() { int t; scanf("%d",&t); while(t--) { cin>>w>>h>>n; memset(map,0,sizeof(map)); memset(sum,0,sizeof(sum)); for(int i=1; i<=n; i++) { cin>>p[i].x>>p[i].y; map[p[i].x][p[i].y]=1; } for (int i = 1; i <= n; i ++) { int xx = p[i].x,yy = p[i].y,x,y,cnt = 0; for (x = xx,y = yy; map[x][y] && y < h; ++y,++cnt); for (x = xx,y = yy; map[x][y] && x < w; ++x,++cnt); for (x = xx,y = yy; map[x][y] && y >= 0; --y,++cnt); for (x = xx,y = yy; map[x][y] && x >= 0; --x,++cnt); sum[0][i] = cnt; } memset(map,0,sizeof(map)); for(int i=1; i<=n; i++) { cin>>p[i].x>>p[i].y; map[p[i].x][p[i].y]=1; } for (int i = 1; i <= n; i ++) { int xx = p[i].x,yy = p[i].y,x,y,cnt = 0; for (x = xx,y = yy; map[x][y] && y < h; ++y,++cnt); for (x = xx,y = yy; map[x][y] && x < w; ++x,++cnt); for (x = xx,y = yy; map[x][y] && y >= 0; --y,++cnt); for (x = xx,y = yy; map[x][y] && x >= 0; --x,++cnt); sum[1][i] = cnt; } sort(sum[0]+1,sum[0]+1+n); sort(sum[1]+1,sum[1]+1+n); int falg=1; for(int i=0; i<n; i++) { if(sum[0][i]!=sum[1][i]) { falg=0; break; } } if(!falg) cout<<"NO"<<endl; else cout<<"YES"<<endl; } return 0; }
思路:把每个点的值设为连续的x轴点数和连续的y轴点数之和。排序之后,如果相等,则两个图相等。证明的话可想而知 过程:一次A了 代码: #include #include int x[110],y[110]; int map[101][101]; int left[10010],right[10010]; int main(){ int cas; int i,j,k; int w,h,n; int tmp; scanf("%d",&cas); for(i = 0; i < cas; i++){ scanf("%d%d%d",&w,&h,&n); memset(map,0,sizeof(map)); for(j = 0; j < n; j++){ scanf("%d%d",&x[j],&y[j]); map[x[j]][y[j]] = 1; } memset(left,0,sizeof(left)); for(j = 0; j < n; j++){ tmp = x[j]; while(tmp >= 0&&map[tmp][y[j]] == 1){ left[j]++; tmp--; } tmp = x[j]+1; while(tmp < w&&map[tmp][y[j]] == 1){ left[j]++; tmp++; } tmp = y[j]-1; while(tmp >= 0&&map[x[j]][tmp] == 1){ left[j]++; tmp--; } tmp = y[j]+1; while(tmp < h&&map[x[j]][tmp] == 1){ left[j]++; tmp++; } } memset(map,0,sizeof(map)); for(j = 0; j < n; j++){ scanf("%d%d",&x[j],&y[j]); map[x[j]][y[j]] = 1; } memset(right,0,sizeof(right)); for(j = 0; j < n; j++){ tmp = x[j]; while(tmp >= 0&&map[tmp][y[j]] == 1){ right[j]++; tmp--; } tmp = x[j]+1; while(tmp < w&&map[tmp][y[j]] == 1){ right[j]++; tmp++; } tmp = y[j]-1; while(tmp >= 0&&map[x[j]][tmp] == 1){ right[j]++; tmp--; } tmp = y[j]+1; while(tmp < h&&map[x[j]][tmp] == 1){ right[j]++; tmp++; } } for(j = 0; j < n; j++){ for(k = 1; k < n; k++){ if(left[k-1] < left[k]){ tmp = left[k-1]; left[k-1] = left[k]; left[k] = tmp; } } } for(j = 0; j < n; j++){ for(k = 1; k < n; k++){ if(right[k-1] < right[k]){ tmp = right[k-1]; right[k-1] = right[k]; right[k] = tmp; } } } for(j = 0; j < n; j++){ if(left[j] != right[j]) break; } if(j == n){ printf("YES\n"); }else{ printf("NO\n"); } } return 0; }
标签:des style blog http color io os ar strong
原文地址:http://www.cnblogs.com/zhangying/p/3970336.html