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 ...
随机推荐
- 在IDEA中创建Maven项目和添加tomcat
IDEA中创建是一种创建maven项目的办法,但不推荐,因为没有使用统一的骨架,可以一开始就选择创建maven项目,步骤如下: 第一步 第二步:设置项目 第三步:进行配置好maven,加上 arche ...
- 【P1330】 封锁阳光大学
两个和谐河蟹不能在同一条边的两端.所以对于每条边.只有一个节点有和谐河蟹 所以说,我们可以将有和谐河蟹的看做一种颜色,或则是状态.没有河蟹看做另一种言颜色 这样边变成了二分图染色 所以嗯~(・∀・) ...
- 第6章 新建工程-寄存器版—零死角玩转STM32-F429系列
第6章 新建工程—寄存器版 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fireg ...
- HTML第二章:列表,表格,媒体元素
第二章:列表,表格,媒体元素 列表:有三种,有序列表,无序列表,定义列表 1.有序列表:<ol></ol> 列表项:<li></li&g ...
- 分页查询关键代码 多条件查询关键代码 删除选中商品关键代码 修改要先回显再修改 修改要先回显再修改 同一业务集中使用同一servlet的方法
分页查询关键代码: 通过servlet转发回来的各种信息进行分页的设计(转发回的信息有 分页查询的List集合 查询的页码 查询的条数 查询的数据库总条数 查询的总页码) 从开始时循环10次出现十个数 ...
- MySQL Limit 限定查询记录数
MySQL Limit 限定查询记录数 MySQL LIMIT MySQL 中 LIMIT 关键字用于限定查询记录返回最大数目. 语法: ... LIMIT offset , rows 该语法中,of ...
- Ubuntu16.04下配置ssh免密登录
Ubuntu16.04下配置ssh免密登录 环境准备:新建两台虚拟机,而且两台虚拟机上都装有Ubuntu16.04的系统,使两台虚拟机之间保持互通状态.分别为两台虚拟机命名为A,B.假设我们要使A虚拟 ...
- Python分布式爬虫抓取知乎用户信息并进行数据分析
在以前的文章中,我写过一篇使用selenium来模拟登录知乎的文章,然后在很长一段时间里都没有然后了... 不过在最近,我突然觉得,既然已经模拟登录到了知乎了,为什么不继续玩玩呢?所以就创了一个项目, ...
- iOS-UICollectionViewController 介绍
废话不多说,列几个列子 (几种情况下的做法): 情景一: 介绍:1. 在UIViewController 上加 UICollectionView (用代码 创建 UICollectionView). ...
- Mybatis中updateByPrimaryKeySelective和updateByPrimaryKey区别
int updateByPrimaryKeySelective(TbItem record); int updateByPrimaryKey(TbItem record); 上面的是逆转工程生成的Ma ...