hdu5386 Cover(暴力,观察)
2015-08-28 21:45
148 查看
题目:
Total Submission(s): 1449 Accepted Submission(s): 498
Special Judge
Problem Description
You have an n∗n
matrix.Every grid has a color.Now there are two types of operating:
L x y: for(int i=1;i<=n;i++)color[i][x]=y;
H x y:for(int i=1;i<=n;i++)color[x][i]=y;
Now give you the initial matrix and the goal matrix.There are
m
operatings.Put in order to arrange operatings,so that the initial matrix will be the goal matrix after doing these operatings
It's guaranteed that there exists solution.
Input
There are multiple test cases,first line has an integer
T
For each case:
First line has two integer n,m
Then n
lines,every line has n
integers,describe the initial matrix
Then n
lines,every line has n
integers,describe the goal matrix
Then m
lines,every line describe an operating
1≤color[i][j]≤n
T=5
1≤n≤100
1≤m≤500
Output
For each case,print a line include
m
integers.The i-th integer x show that the rank of x-th operating is
i
Sample Input
Sample Output
Author
SXYZ
Source
2015 Multi-University Training Contest 8
题意:给一个初始矩阵和目标矩阵,以及m个操作,让你把m个操作排序使得按照这些操作可以从初始矩阵变换为目标矩阵。
思路:由于操作是把整行或整列替换成一个新的值,所以之前对该行(列)的操作都会被后面的操作覆盖掉,我们只要根据目标矩阵的值不断确定最后的操作就可以了,直到把m个操作确定完。至于确定最后的操作,只要目标矩阵中该行(列)的值和覆盖的值相同,那么它就是最后的操作。
代码:
Cover
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1449 Accepted Submission(s): 498
Special Judge
Problem Description
You have an n∗n
matrix.Every grid has a color.Now there are two types of operating:
L x y: for(int i=1;i<=n;i++)color[i][x]=y;
H x y:for(int i=1;i<=n;i++)color[x][i]=y;
Now give you the initial matrix and the goal matrix.There are
m
operatings.Put in order to arrange operatings,so that the initial matrix will be the goal matrix after doing these operatings
It's guaranteed that there exists solution.
Input
There are multiple test cases,first line has an integer
T
For each case:
First line has two integer n,m
Then n
lines,every line has n
integers,describe the initial matrix
Then n
lines,every line has n
integers,describe the goal matrix
Then m
lines,every line describe an operating
1≤color[i][j]≤n
T=5
1≤n≤100
1≤m≤500
Output
For each case,print a line include
m
integers.The i-th integer x show that the rank of x-th operating is
i
Sample Input
1 3 5 2 2 1 2 3 3 2 1 3 3 3 3 3 3 3 3 3 3 H 2 3 L 2 2 H 3 3 H 1 3 L 2 3
Sample Output
5 2 4 3 1
Author
SXYZ
Source
2015 Multi-University Training Contest 8
题意:给一个初始矩阵和目标矩阵,以及m个操作,让你把m个操作排序使得按照这些操作可以从初始矩阵变换为目标矩阵。
思路:由于操作是把整行或整列替换成一个新的值,所以之前对该行(列)的操作都会被后面的操作覆盖掉,我们只要根据目标矩阵的值不断确定最后的操作就可以了,直到把m个操作确定完。至于确定最后的操作,只要目标矩阵中该行(列)的值和覆盖的值相同,那么它就是最后的操作。
代码:
#include <cstdlib> #include <cctype> #include <cstring> #include <cstdio> #include <cmath> #include<climits> #include <algorithm> #include <vector> #include <string> #include <iostream> #include <sstream> #include <map> #include <set> #include <queue> #include <stack> #include <fstream> #include <numeric> #include <iomanip> #include <bitset> #include <list> #include <stdexcept> #include <functional> #include <utility> #include <ctime> using namespace std; #define PB push_back #define MP make_pair #define REP(i,x,n) for(int i=x;i<(n);++i) #define FOR(i,l,h) for(int i=(l);i<=(h);++i) #define FORD(i,h,l) for(int i=(h);i>=(l);--i) #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define RI(X) scanf("%d", &(X)) #define RII(X, Y) scanf("%d%d", &(X), &(Y)) #define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z)) #define DRI(X) int (X); scanf("%d", &X) #define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y) #define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z) #define OI(X) printf("%d",X); #define RS(X) scanf("%s", (X)) #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second #define Swap(a, b) (a ^= b, b ^= a, a ^= b) #define Dpoint strcut node{int x,y} #define cmpd int cmp(const int &a,const int &b){return a>b;} /*#ifdef HOME freopen("in.txt","r",stdin); #endif*/ const int MOD = 1e9+7; typedef vector<int> VI; typedef vector<string> VS; typedef vector<double> VD; typedef long long LL; typedef pair<int,int> PII; //#define HOME int Scan() { int res = 0, ch, flag = 0; if((ch = getchar()) == '-') //判断正负 flag = 1; else if(ch >= '0' && ch <= '9') //得到完整的数 res = ch - '0'; while((ch = getchar()) >= '0' && ch <= '9' ) res = res * 10 + ch - '0'; return flag ? -res : res; } /*----------------PLEASE-----DO-----NOT-----HACK-----ME--------------------*/ int a[105][105]; struct op { char o; int x; int y; }; op p[505]; int ans[505]; int vis[505]; int main() { int T; //freopen("in.txt","r",stdin); RI(T); while(T--) { int n,m; RII(n,m); MS0(vis); for(int i=0;i<n;i++) for(int j=0;j<n;j++) RI(a[i][j]); for(int i=0;i<n;i++) for(int j=0;j<n;j++) RI(a[i][j]); for(int i=0;i<m;i++) { getchar(); char str[10]; scanf("%s%d%d",str,&p[i].x,&p[i].y); p[i].o=str[0]; } int t=0; while(t<m) { for(int i=0;i<m;i++) if(!vis[i]) { if(p[i].o=='L') { int x=p[i].x-1; int y=p[i].y; int ok=1; for(int j=0;j<n;j++) if(a[j][x]&&a[j][x]!=y) { ok=0; break; } if(ok) { ans[t++]=i+1; for(int j=0;j<n;j++) a[j][x]=0; vis[i]=1; } } else { int x=p[i].x-1; int y=p[i].y; int ok=1; for(int j=0;j<n;j++) { if(a[x][j]&&a[x][j]!=y) { ok=0; break; } } if(ok) { ans[t++]=i+1; for(int j=0;j<n;j++) a[x][j]=0; vis[i]=1; } } } } for(int i=m-1;i>0;i--) printf("%d ",ans[i]); printf("%d\n",ans[0]); } return 0; }
相关文章推荐
- scala实现设计模式之外观模式
- leetcode Palindrome Number java编程学习(三)
- OC基础-零基础学习Objective-C:第一部分.类和对象
- jquery hover延时
- 【软工6】软件开发小组
- DirectX3D游戏开发三 绘制流水线
- 【软工6】软件开发小组
- spring MVC jsp页面EL表达式无效
- python 进程multiprocessing库
- 数据挖掘的五个误区
- mac常用操作
- 有向图中单个源点到终点的最短路径--Dijkstra算法与实现
- PHP语言学习(环境安装)
- 线程进程
- 在C#中通过lua调用C#中的类方法
- 《TCP/IP详解卷1:协议》——第2章:链路层(转载)
- Linux内核同步机制之(四):spin lock
- JavaScript内核笔记04-数组
- 矩阵基本操作(加减乘、求逆、转置)
- 客户细分的7个诀窍