UVa512 (implement)
来源:互联网 发布:淘宝定金是什么意思 编辑:程序博客网 时间:2024/06/11 21:01
AC代码:
/** 20171030*///#define LOCAL#include <cstdio>#include <cstring>#include <algorithm>#include <cstdlib>using namespace std;#define maxn 10000struct Command{ char s[5]; int r1,c1,r2,c2; int A; int a[15];}cmd[maxn];int loc = 0;void solve(int x,int y){ int tx = x; int ty = y; int tmp = 0; for(int i=0;i<loc;i++) { //exchange if(cmd[i].s[0]=='E') { //printf("!!! EX %d %d %d %d tx:%d ty:%d\n",cmd[i].r1,cmd[i].c1,cmd[i].r2,cmd[i].c2,tx,ty); //the first condition if(tx==cmd[i].r1&&ty==cmd[i].c1){tx=cmd[i].r2;ty=cmd[i].c2;} //the second condition else if(tx==cmd[i].r2&&ty==cmd[i].c2){tx=cmd[i].r1;ty=cmd[i].c1;} } //delete if(cmd[i].s[0]=='D') { //delete r if(cmd[i].s[1]=='R') { tmp = 0; for(int j=0;j<cmd[i].A;j++) { if(tx>cmd[i].a[j]) tmp++; if(tx==cmd[i].a[j]){printf("Cell data in (%d,%d) GONE\n",x,y);return ;} } tx-=tmp; } //delete c if(cmd[i].s[1]=='C') { tmp = 0; for(int j=0;j<cmd[i].A;j++) { if(ty>cmd[i].a[j]) tmp++; if(ty==cmd[i].a[j]){ printf("Cell data in (%d,%d) GONE\n",x,y);return ;} } ty-=tmp; } } //insert if(cmd[i].s[0]=='I') { if(cmd[i].s[1]=='R') { tmp = 0; for(int j=0;j<cmd[i].A;j++) if(tx>=cmd[i].a[j]) tmp++; tx+=tmp; } if(cmd[i].s[1]=='C') { tmp = 0; for(int j=0;j<cmd[i].A;j++) if(ty>=cmd[i].a[j]) tmp++; ty+=tmp; } } //printf("!!! %d %d\n",tx,ty); } printf("Cell data in (%d,%d) moved to (%d,%d)\n",x,y,tx,ty);}int main(){ #ifdef LOCAL freopen("test.txt","r",stdin); freopen("b.txt","w",stdout); #endif int r,c; int cnt = 0; while(scanf("%d%d",&r,&c)==2&&r) { loc = 0; memset(cmd,0,sizeof(cmd)); int n; if(cnt>0) printf("\n"); printf("Spreadsheet #%d\n",++cnt); scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%s",cmd[loc].s); if(cmd[loc].s[0]=='E') { scanf("%d%d%d%d",&cmd[loc].r1,&cmd[loc].c1,&cmd[loc].r2,&cmd[loc].c2); } else { scanf("%d",&cmd[loc].A); for(int j=0;j<cmd[loc].A;j++) { scanf("%d",&cmd[loc].a[j]); } } loc++; } scanf("%d",&n); for(int i=0;i<n;i++) { int x,y; scanf("%d%d",&x,&y); solve(x,y); } } return 0;}
随机生成测试数据代码,用于与AC代码文件对碰,文件对碰代码http://blog.csdn.net/shelldawn/article/details/78401066
/** 20171030*/#include <cstdio>#include <ctime>#include <cstdlib>#include <algorithm>using namespace std;char str[5][5] = {"EX","DR","DC","IC","IR"};const int allnum = 10;//0<=n<=lvoid solve(int n,int l){ int last = 0; int now = 0; for(int i=1;i<=n;i++) { now = last+rand()%(l-(n-i)-last)+1; printf(" %d",now); last = now; }}int main(){ freopen("test.txt","w",stdout); srand(time(NULL)); for(int i=0;i<allnum;i++) { int r = rand()%50+1; int c = rand()%50+1; int tr = r; int tc = c; printf("%d %d\n",r,c); printf("%d\n",allnum); for(int j=0;j<allnum;j++) { int k = rand()%5; if(k==0) { if(tr==0||tc==0) j--; else { printf("%s",str[k]); printf(" %d %d %d %d\n",rand()%tr+1,rand()%tc+1,rand()%tr+1,rand()%tc+1); } }else if(k==1) { printf("%s",str[k]); int f = min(15,rand()%(tr+1)); printf(" %d",f); solve(f,tr); tr-=f; }else if(k==2) { printf("%s",str[k]); int f = min(15,rand()%(tc+1)); printf(" %d",f); solve(f,tc); tc-=f; }else if(k==3) { printf("%s",str[k]); int f = min(15,rand()%(tc+1)); printf(" %d",f); solve(f,tc); tc+=f; }else { printf("%s",str[k]); int f = min(15,rand()%(tr+1)); printf(" %d",f); solve(f,tr); tr+=f; } printf("\n"); } printf("%d\n",allnum); for(int j=0;j<allnum;j++) { printf("%d %d\n",rand()%r+1,rand()%c+1); } } printf("0 0\n"); return 0;}
阅读全文
0 0
- UVa512 (implement)
- UVa512
- uva512心得
- UVA512 - Spreadsheet Tracking
- uva512追踪电子表格
- UVa512 - Spreadsheet Tracking
- UVALive5198 UVA512 Spreadsheet Tracking
- UVa512-Spreadsheet Tracking
- UVa512 Spreadsheet Tracking
- #leetcode#Implement strStr()
- uva512追踪电子表格中的单元格
- [UVA512]Spreadsheet Tracking[模拟][STL]
- Implement strStr()(3 ways)
- LeetCode(28)Implement strStr()
- 28. Implement strStr()(重要!)
- leetcode_c++:Implement strStr() (028)
- 28. Implement strStr()(64.79%)
- Implement strStr(字符串查找)
- LeetCode--Group Anagrams(Python)
- idea构建maven项目。
- 阿里云栖大会100位顶级大咖演讲PPT+视频全分享!
- Graph Cut
- hbuilder使用ftp和github
- UVa512 (implement)
- Oracle EBS 大量并发请求提交导致内存不足系统杀死Java JVM进程
- 关于bootloader
- key事件
- 在ubuntu16.04下安装clion
- 使用opencv,在iOS环境下检测边角点,然后画出最大矩形
- Python爬虫(二)使用urllib来爬点东西
- workqueue
- Struts2:action的三种开发方式