HDU 4671 Backup Plan
来源:互联网 发布:3344ff新域名 编辑:程序博客网 时间:2024/05/29 14:12
Backup Plan
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 486 Accepted Submission(s): 224
Special Judge
Total Submission(s): 486 Accepted Submission(s): 224
Special Judge
Problem Description
Makomuno has N servers and M databases. All databases are synchronized among all servers and each database has a ordered list denotes the priority of servers to access. This list is guaranteed to be a valid permutation of all servers.
Every time someone wants to execute queries on a certain database, he will send a request to the first server in the list. If it's dead, he will simply turn to the next one. Otherwise a working copy of the database is found, and this copy is called active.
Now, given N and M, Makomuno wants to find a permutation for each database which could assure that all servers are load-balanced. Moreover, Makomuno hopes the system will be load-balanced even ifexactly one server is broken.
Note that if we call the number of active copies on i-th server Ai, then load-balanced means max∣Ai - Aj∣≤1 for any i and j in non broken servers set. We won't consider broken servers in this case.
Every time someone wants to execute queries on a certain database, he will send a request to the first server in the list. If it's dead, he will simply turn to the next one. Otherwise a working copy of the database is found, and this copy is called active.
Now, given N and M, Makomuno wants to find a permutation for each database which could assure that all servers are load-balanced. Moreover, Makomuno hopes the system will be load-balanced even ifexactly one server is broken.
Note that if we call the number of active copies on i-th server Ai, then load-balanced means max∣Ai - Aj∣≤1 for any i and j in non broken servers set. We won't consider broken servers in this case.
Input
The input contains several test cases, terminated by EOF.
Each test case has one line containing two integer N ( 2≤N≤100) and M ( 1≤M≤100).
Each test case has one line containing two integer N ( 2≤N≤100) and M ( 1≤M≤100).
Output
For each case output M lines, the i-th line contains a permutation of all servers, indicating the expected order. Servers are numbered from 1 to n.
Sample Input
5 3
Sample Output
2 4 3 1 51 5 4 2 33 5 2 4 1HintIn the sample test case, the active copies of these databases are on server 2,1 and 3 in normal state. A = {1,1,1,0,0}If server 1 or 3 has broken, server 5 will take its work. In case we lost server 2, the second database will use server 4 instead. A = {1,BROKEN,1,1,0}It's clear that in any case this system is load-balanced according to the plan in sample output.
Source
2013 Multi-University Training Contest 7
Recommend
zhuyuanchen520
找了好久的规律,注意处理好细节
找了好久的规律,注意处理好细节
#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#define N 110using namespace std;int main(){ //freopen("data.in","r",stdin); int n,m; while(scanf("%d %d",&n,&m)!=EOF) { if(n==m) { for(int i=1;i<=m;i++) { printf("%d",i); for(int j=1;j<=n;j++) { if(j!=i) { printf(" %d",j); } } printf("\n"); } continue; } if(n>m) { for(int i=1;i<=m;i++) { printf("%d %d",i,n); for(int j=1;j<=n-1;j++) { if(j!=i) { printf(" %d",j); } } printf("\n"); } continue; } if(n<m) { int T = m/n; int sta=1,end=n; if(m%n==0) { for(int i=1;i<=n;i++) { int x=i+1; if(i==n) { x=1; } for(int j=1;j<=T;j++) { printf("%d",i); printf(" %d",x); for(int y=1;y<=n;y++) { if(y==i||y==x) { continue; } printf(" %d",y); } printf("\n"); x+=1; if(x==n+1) { x=1; } if(x==i) { x+=1; } if(x==n+1) { x=1; } } } continue; } end = m%n; T = T+1; int u=end+1,v=n; for(int i=1;i<=end;i++) { int x=u; for(int j=1;j<=T;j++) { printf("%d",i); printf(" %d",x); for(int y=1;y<=n;y++) { if(y==i||y==x) { continue; } printf(" %d",y); } printf("\n"); if(x<v) { x+=1; }else { x=1; } if(x==i) { x+=1; } } } for(int i=u;i<=n;i++) { int x = u; if(x==i) { x+=1; } if(n-u+1==1) { x=1; } for(int j=1;j<=T-1;j++) { printf("%d",i); printf(" %d",x); for(int y=1;y<=n;y++) { if(y==i||y==x) { continue; } printf(" %d",y); } printf("\n"); x+=1; if(x==i) { x+=1; } if(x==n+1) { x = 1; } if(x==i) { x+=1; } } } } } return 0;}
- HDU 4671 Backup Plan
- hdu-4671 Backup Plan
- HDU 4671 Backup Plan
- HDU 4671 Backup Plan (水题)
- hdu 4671 Backup Plan 构造
- HDU 4671 Backup Plan 解题报告
- hdu 4671——Backup Plan
- hdu 4671 Backup Plan(构造)
- HDU 4671 Backup Plan (2013多校联合7 1006)
- HDOJ 4671 Backup Plan 构造优先队列
- Resolved TFS backup issue>[ Backup Plan Verifications ] A backup plan already exists for this Tfs co
- Resolved TFS backup issue>Gramt Backup Plan Permission
- HDU4671 Backup Plan(构造序列-多校七)
- hdu 3377 Plan
- HDU 2103 Family Plan
- hdu 3377 Plan
- hdu 3757 Evacuation Plan
- HDU 3757 Evacuation Plan
- 成员函数 回调函数
- 老码农教你学英语
- 安卓应用桌面小图标
- 每个上班的人都应该懂劳动法
- 账户管理命令 useradd、groupadd
- HDU 4671 Backup Plan
- hdu 2686最小费用最大流问题
- 在C/C++中获取可执行文件的图标和信息
- 委托入门(C#)
- Android系统启动过程
- hdu 1548 A strange lift(搜索or最短路)
- android的开机动画制作要点
- Current Contest(poj3294,后缀数组)
- hdu 2577