Backup Plan

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 93    Accepted Submission(s): 36
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 if exactly 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).
 
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 5
1 5 4 2 3
3 5 2 4 1

Hint

In 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
 
Recommend
zhuyuanchen520
 

题目意思很难懂,自己去理解吧、

就是要构造出一个m*n的矩阵

我的做法就是

1) n>=m

那么第一列就放1,2,....m

第二列放n n n n n n n n (如果n==m的情况,那么在第一列是n的时候放n-1).

其余列放没有在第一列和第二列出现的既可。

2) n < m

这种情况:

第一列的方法是1 2 3 ....n  1  2  3 ....n  1  2  3...这样循环

第二列。

对于第1列放1的行,就是n*k+1(k=0,1,2...)行,从n,n-1,n-2,...这样循环放,遇到1就跳过。

对于放2的行一样处理,遇到2跳过

对于其它数也一样。

然后其余列只有和前两列不同既可

 /* **********************************************
Author : kuangbin
Created Time: 2013/8/13 13:34:52
File Name : F:\2013ACM练习\2013多校7\1006.cpp
*********************************************** */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
using namespace std;
int a[][];
bool used[];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,m;
while(scanf("%d%d",&n,&m) == )
{
if(n >= m)
{
for(int i = ;i <= m;i++)
{
a[i][] = i;
a[i][] = n;
if(a[i][]==n)a[i][] = n-;
memset(used,false,sizeof(used));
used[a[i][]] = used[a[i][]] = true;
int t = ;
for(int j = ;j <= n;j++)
{
while(used[t])t++;
a[i][j] = t++;
}
}
}
else
{
int t = ;
for(int i = ;i <= m;i++)
{
a[i][] = t++;
if(t > n)t = ;
}
for(int i = ;i <= n;i++)
{
if(i < n)t = n;
else t = n-;
for(int j = ;j*n+i <= m;j++)
{
a[j*n+i][] = t;
t--;
// printf("%d %d %d\n",i,j,t);
if(t == )t = n;
if(t == i)t--;
if(t==)t=n;
} }
for(int i = ;i <= m;i++)
{
memset(used,false,sizeof(used));
used[a[i][]] = used[a[i][]] = true;
int t = ;
for(int j = ;j <= n;j++)
{
while(used[t])t++;
a[i][j] = t++;
}
}
}
for(int i = ;i <= m;i++)
{
for(int j = ;j <= n;j++)
{
printf("%d",a[i][j]);
if(j < n)printf(" ");
else printf("\n");
}
}
}
return ;
}

HDU 4671 Backup Plan (2013多校7 1006题 构造)的更多相关文章

  1. HDU 4681 String(2013多校8 1006题 DP)

    String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Subm ...

  2. HDU 4691 Front compression (2013多校9 1006题 后缀数组)

    Front compression Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Othe ...

  3. HDU 4705 Y (2013多校10,1010题,简单树形DP)

    Y Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...

  4. HDU 4704 Sum (2013多校10,1009题)

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submi ...

  5. HDU 4699 Editor (2013多校10,1004题)

    Editor Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

  6. HDU 4696 Answers (2013多校10,1001题 )

    Answers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total S ...

  7. HDU 4678 Mine (2013多校8 1003题 博弈)

    Mine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  8. HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  9. hdu 4671 Backup Plan(签到题)

    错成那样,还以为是卡时间卡精度的变态题,结果就那么ac了= = 悔死我了 题意就不概述了,只要处理前两列即可.其中第一列顺序直接扫一遍,第二列要先处理较少的那几种.我是接着第一列用 head[] 继续 ...

随机推荐

  1. 91.Decode Ways---dp

    题目链接:https://leetcode.com/problems/decode-ways/description/ 题目大意:将给出的字符串解码,问有多少种解码方式.解码按照“ABC...Z&qu ...

  2. fastJson去掉指定字段

    public static String filterFieldsJson(Object src, Class<?> clazz, String... args) { SimpleProp ...

  3. [ python ] 线程的操作

    目录 (见右侧目录栏导航) - 1. 前言    - 1.1 进程    - 1.2 有了进程为什么要有线程    - 1.3 线程的出现    - 1.4 进程和线程的关系    - 1.5 线程的 ...

  4. C#子线程中更新ui

    本文实例总结了C#子线程更新UI控件的方法,对于桌面应用程序设计的UI界面控制来说非常有实用价值.分享给大家供大家参考之用.具体分析如下: 一般在winform C/S程序中经常会在子线程中更新控件的 ...

  5. HTTP协议头注射漏洞实例

    HTTP 响应头文件中包含未经验证的数据会引发 cache-poisoning.cross-site scripting.cross-user defacement.page hijacking.co ...

  6. Linux 基础——关机重启命令shutdown、reboot等

    一.关机重启命令的作用 相信对于接触过电脑的人来说,特别是对于windows系统来说,如果长时间使用不经重启的话会出现一点点卡顿的感觉.但是当重启整个系统后,这点点卡顿的感觉好像又没了,重启后wind ...

  7. [笔记] 几个前端bug的解决方案

    jQuery UI下被拖动的元素上飘 症状出现在几乎所有浏览器里.使用 1.10.x 的draggable,在滚动栏下移(即非处于页面顶部)的时候拖动draggable的元素,它会向上跳一段距离.解决 ...

  8. AC日记——[USACO5.4]奶牛的电信Telecowmunication 洛谷 P1345

    [USACO5.4]奶牛的电信Telecowmunication 思路: 水题: 代码: #include <cstdio> #include <cstring> #inclu ...

  9. ref:Java安全之反序列化漏洞分析(简单-朴实)

    ref:https://mp.weixin.qq.com/s?__biz=MzIzMzgxOTQ5NA==&mid=2247484200&idx=1&sn=8f3201f44e ...

  10. windows下重置mysql的root密码方法介绍(转)

    自己在内网操作的,遇到了一些的问题,其中一个是需要重置密码的,所以网上找了两篇文章,都有一些借鉴的地方. 版本mysql5.7.2,linux系统 除了参考文章还有几点说明: service mysq ...