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 ...
随机推荐
- 谷歌浏览器兼容IE插件
谷歌浏览器兼容IE插件 http://pan.baidu.com/s/1i31hspf
- 前端css样式及选择器
标题: 1.scc概述 2.行内样式 3.内接样式 4.外接样式(链接式) 推荐使用 5.外接样式(导入式) 6.嵌套规则 7.css选择器 1.scc(Cascading Style Shee ...
- 4.vue引入axios同源跨域
前言: 跨域方案有很多种,既然我们用到了Vue,那么就使用vue提供的跨域方案. 解决方案: 1.修改HttpRequestUtil.js import axios from 'axios' expo ...
- poj_2689_Prime Distance
The branch of mathematics called number theory is about properties of numbers. One of the areas that ...
- poj_1284_Primitive root
We say that integer x, 0 < x < p, is a primitive root modulo odd prime p if and only if the se ...
- JDK1.8简单配置环境变量---两步曲
鄙人最近重新装完系统之后,在安装和配置jdk1.8的时候,发现网上许多教程配置jdk环境变量时都还在沿用传统的方式配置,但是随着技术的更新,完全没有必要那么麻烦了. 下载和安装jdk的教程,在这里就不 ...
- docker启用镜像常用脚本
语法:docker run [OPTIONS] IMAGE [COMMAND] [ARG...] OPTIONS说明:-a stdin: 指定标准输入输出内容类型,可选 STDIN/STDOUT/ST ...
- kafka单机环境搭建及其基本使用
最近在搞kettle整合kafka producer插件,于是自己搭建了一套单机的kafka环境,以便用于测试.现整理如下的笔记,发上来和大家分享.后续还会有kafka的研究笔记,依然会与大家分享! ...
- TP3.2.3 页面跳转后 Cookie 失效 —— 参考解决方案
一.问题描述 接手一个项目,使用ThinkPhp3.2.3,在线上环境( Centos7.4 + Nginx1.14 + MySQL5.7 + PHP7.2.4 )运行没有问题, 在本地环境( php ...
- Effective Approaches to Attention-based Neural Machine Translation(Global和Local attention)
这篇论文主要是提出了Global attention 和 Local attention 这个论文有一个译文,不过我没细看 Effective Approaches to Attention-base ...