HDU 4671 Backup Plan 构造
负载是否平衡只与前两列有关,剩下的只要与前两列不重复就随便放。
第一列我们按1-n这样循环放,第二列每次找个数最少的那个服务器放。
#include <cstdio>
#include <cstring>
#include <cstdlib> using namespace std; const int MAXN = ; int N, M;
int mat[MAXN][MAXN];
int cnt[MAXN];
int ori[MAXN];
bool vis[MAXN]; void show()
{
for ( int i = ; i <= M; ++i )
{
for ( int j = ; j <= N; ++j )
{
if ( j != ) putchar(' ');
printf( "%d", mat[i][j] );
}
puts("");
}
//puts("=========");
return;
} void FangHang( int *a )
{
memset( vis, false, sizeof(vis) );
vis[ a[] ] = true;
vis[ a[] ] = true; for ( int i = ; i <= N; ++i )
{
for ( int j = ; j <= N; ++j )
if ( !vis[j] )
{
a[i] = j;
vis[j] = true;
break;
}
} return;
} int GetMin( int now )
{
int minn = << ;
int ansi;
for ( int i = ; i <= N; ++i )
{
if ( i == now ) continue;
if ( cnt[i] < minn )
{
minn = cnt[i];
ansi = i;
}
}
return ansi;
} void solved()
{
memset( cnt, , sizeof(cnt) );
for ( int i = ; i <= M; ++i )
++cnt[ mat[i][] ]; int fang = ;
int cur = ;
for ( int i = ; i <= N; ++i ) ori[i] = cnt[i];
while ( fang < M )
{
int minn;
int j = ;
while ( j <= M )
{
minn = GetMin(cur);
for ( ; j <= M; ++j )
{
if ( mat[j][] == cur && mat[j][] == - )
{
mat[j][] = minn;
++cnt[ minn ];
++fang;
break;
}
}
}
for ( int i = ; i <= N; ++i ) cnt[i] = ori[i];
++cur;
} for ( int i = ; i <= M; ++i )
{
FangHang( mat[i] );
} return;
} int main()
{
while ( scanf( "%d%d", &N, &M ) == )
{
memset( mat, -, sizeof(mat) );
int i = , j = ;
while ( i <= M )
{
mat[i][] = j;
++i, ++j;
if ( j > N ) j = ;
}
solved();
show();
}
return ;
}
HDU 4671 Backup Plan 构造的更多相关文章
- HDU 4671 Backup Plan (2013多校7 1006题 构造)
Backup Plan Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- hdu 4671 Backup Plan(签到题)
错成那样,还以为是卡时间卡精度的变态题,结果就那么ac了= = 悔死我了 题意就不概述了,只要处理前两列即可.其中第一列顺序直接扫一遍,第二列要先处理较少的那几种.我是接着第一列用 head[] 继续 ...
- hdu4671 Backup Plan ——构造题
link:http://acm.hdu.edu.cn/showproblem.php?pid=4671 其实是不难的那种构造题,先排第一列,第二列从后往前选. #include <iostrea ...
- HDU-4671 Backup Plan 构造解
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4671 假设是3 m,首先按照第一列按照1 2 3 1 2 3 1...排下去,然后个数就是一个 (m/ ...
- Create maintenance backup plan in SQL Server 2008 R2 using the wizard
You will need to identify how you want your maintenance plan to be setup. In this example the mainte ...
- HDU 5573 Binary Tree 构造
Binary Tree 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5573 Description The Old Frog King lives ...
- hdu 5015 233 Matrix(构造矩阵)
http://acm.hdu.edu.cn/showproblem.php?pid=5015 由于是个二维的递推式,当时没有想到能够这样构造矩阵.从列上看,当前这一列都是由前一列递推得到.依据这一点来 ...
- HDU 5813 Elegant Construction 构造
Elegant Construction 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...
- HDU 3080 The plan of city rebuild(prim和kruskal)
The plan of city rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
随机推荐
- sz 命令
sz命令 下载文件命令 sz 文件名
- PHP调试小错误汇总
1.中文显示乱码 解决:加上header('Content-type:text'); 2.Unable to find the wrapper "https 解决:到php.ini中把ext ...
- C# 操作符与表达式
C#保留了C++所有的操作符,其中指针操作符(*和->)与引用操作符(&)需要有unsafe的上下文.C#摈弃了范围辨析操作符(::),一律改为单点操作符(.).我们不再阐述那些保留的C ...
- django+xadmin在线教育平台(十)
剩余app model注册 courses注册 新建courses/adminx.py: # encoding: utf-8 __author__ = 'mtianyan' __date__ = '2 ...
- python实现简单关联规则Apriori算法
from itertools import combinations from copy import deepcopy # 导入数据,并剔除支持度计数小于min_support的1项集 def lo ...
- Thinkphp 取消Url默认模块的现实
例子http://www.tp.com/home/index/index 想要现实的效果是:http://www.tp.com/index/index 1是通过配置路由来达到目的 2通过配置首页的入口 ...
- Java高并发之同步异步
1.概念理解: 2.同步的解决方案: 1).基于代码 synchronized 关键字 修饰普通方法:作用于当前实例加锁,进入同步代码前要获得当前实例的锁. 修饰静态方法:作用于当前类对象加锁,进入同 ...
- DrawGrid 做图片显示 代码简单 参考性强 (Delphi7)
运行效果图 源码 http://files.cnblogs.com/lwm8246/DrawGrid_demo.rar procedure TfrmMain.GridDrawCell(Send ...
- [KMP][BZOJ1355][Baltic2009]Radio Transmission
题面 Description 给你一个字符串,它是由某个字符串不断自我连接形成的. 但是这个字符串是不确定的,现在只想知道它的最短长度是多少. Input 第一行给出字符串的长度,\(1 < L ...
- sprintf()函数使用异常
调试STM32F103,比如如下代码:使用springf函数,这个函数是把最后两个参数先格式化成字符串 ,输出到ERROR_STRING,如果他们合并的长度大于30会出现深情况? ] sprintf( ...