The 2015 China Collegiate Programming Contest K Game Rooms hdu 5550
Game Rooms
Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 305 Accepted Submission(s): 84
Luckily, you know who will work where in this building (everyone has picked out offices). You know that there will be Ti table tennis players and Pi pool players on each floor. Our goal is to minimize the sum of distances for each employee to their nearest game room. The distance is the difference in floor numbers: 0 if an employee is on the same floor as a game room of their desired type, 1 if the nearest game room of the desired type is exactly one floor above or below the employee, and so on.
2
10 5
4 3
In the first case, you can build a table tennis game room on the first floor and a pool game room on the second floor.
In this case, the 5 pool players on the first floor will need to go one floor up, and the 4 table tennis players on the second floor will need to go one floor down. So the total distance is 9.
#include <cstdio>
#include <iostream>
using namespace std; const int N = ;
typedef long long LL;
const LL MLL = 1000000000000000001LL;
int n, arr[N][];
LL distDown[N][], distUp[N][], sum[N][], dp[N][], ans; inline LL Up(int l, int r, bool s)
{
if(l > r) return ;
return (distUp[l][s ^ ] - distUp[r + ][s ^ ]) -
(sum[r][s ^ ] - sum[l - ][s ^ ]) * (n - r);
} inline LL Down(int l, int r, bool s)
{
if(l > r) return ;
return (distDown[r][s ^ ] - distDown[l - ][s ^ ]) -
(sum[r][s ^ ] - sum[l - ][s ^ ]) * (l - );
} inline LL Calc(int l, int r, bool state)
{
if(l == )
{
return Up(l, r, state);
}
int mid = (l + r) >> ;
return Up(mid + , r, state) + Down(l, mid, state);
} inline void Solve()
{
scanf("%d", &n);
for(int i = ; i <= n; i++)
for(int j = ; j < ; j++) scanf("%d", &arr[i][j]); for(int i = ; i < ; i++)
{
distDown[][i] = ;
for(int j = ; j <= n; j++)
{
distDown[j][i] = distDown[j - ][i] + 1LL * arr[j][i] * j;
sum[j][i] = sum[j - ][i] + arr[j][i];
}
distUp[n + ][i] = ;
for(int j = n; j >= ; j--)
distUp[j][i] = distUp[j + ][i] + 1LL * arr[j][i] * (n + - j);
} ans = MLL;
dp[][] = dp[][] = ;
for(int i = ; i < n; i++)
{
dp[i][] = dp[i][] = MLL;
for(int j = ; j < i; j++)
{
dp[i][] = min(dp[i][], dp[j][] + Calc(j + , i, ));
dp[i][] = min(dp[i][], dp[j][] + Calc(j + , i, ));
} ans = min(ans, dp[i][] + Down(i + , n, ));
ans = min(ans, dp[i][] + Down(i + , n, ));
}
cout << ans << endl;
} int main()
{
int test;
scanf("%d", &test);
for(int testnumber = ; testnumber <= test; testnumber++)
{
printf("Case #%d: ", testnumber);
Solve();
}
return ;
}
The 2015 China Collegiate Programming Contest K Game Rooms hdu 5550的更多相关文章
- The 2015 China Collegiate Programming Contest G. Ancient Go hdu 5546
Ancient Go Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- The 2015 China Collegiate Programming Contest A. Secrete Master Plan hdu5540
Secrete Master Plan Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- The 2015 China Collegiate Programming Contest Game Rooms
Game Rooms Time Limit: 4000/4000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- The 2015 China Collegiate Programming Contest C. The Battle of Chibi hdu 5542
The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- The 2015 China Collegiate Programming Contest L. Huatuo's Medicine hdu 5551
Huatuo's Medicine Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
- The 2015 China Collegiate Programming Contest H. Sudoku hdu 5547
Sudoku Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Subm ...
- The 2015 China Collegiate Programming Contest E. Ba Gua Zhen hdu 5544
Ba Gua Zhen Time Limit: 6000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- The 2015 China Collegiate Programming Contest D.Pick The Sticks hdu 5543
Pick The Sticks Time Limit: 15000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
- The 2015 China Collegiate Programming Contest -ccpc-c题-The Battle of Chibi(hdu5542)(树状数组,离散化)
当时比赛时超时了,那时没学过树状数组,也不知道啥叫离散化(貌似好像现在也不懂).百度百科--离散化,把无限空间中无限的个体映射到有限的空间中去,以此提高算法的时空效率. 这道题是dp题,离散化和树状数 ...
随机推荐
- XPath的基本使用
XPath XPath 使用路径表达式来选取 XML 文档中的节点或节点集. 路径表达式 结果 bookstore 选取 bookstore 元素的所有子节点. /bookstore 选取根元素 bo ...
- python基础语法(二)
本文主要包括以下内容 函数 切片 迭代 列表生成式 生成器 迭代器 函数 定义函数 定义函数 在Python中,定义一个函数要使用def语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块 ...
- ssh -v root@xxxxx 显示登录的细节
[root@ok .ssh]# ssh -v root@10.100.2.84 OpenSSH_5.3p1, OpenSSL Feb debug1: Reading configuration dat ...
- Unity依赖注入使用
构造器注入(Constructor Injection):IoC容器会智能地选择选择和调用适合的构造函数以创建依赖的对象.如果被选择的构造函数具有相应的参数,IoC容器在调用构造函数之前会自定义创建相 ...
- Filp Game
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25573 Accepted: 11052 题目链接: ...
- 学习ASP.NET缓存机制
缓存是大型BS架构网站的性能优化通用手段,之前知道有这个概念,并且也知道很重要,但是一直没静下心来了解.这次借着学习PetShop源码的机会熟悉一下ASP.NET基本的缓存机制(生产环境中的真实缓存有 ...
- WIN10 新建ORACLE实例
1 管理员身份进入CMD环境,执行DBCA命令,在弹出窗口的引导中,完成实例创建 2 如果在创建过程中没有选择适当的字符集(最好采用默认字符集),如下图所示,在进入PLSQL DEVELOPER的时候 ...
- freemarker 实现对URL的安全编码
[#setting url_escaping_charset='utf-8'] ${yourstr?url}
- Solr入门之(4)配置文件solr.xml
<?xml version="1.0" encoding="UTF-8" ?> <!-- This is an example of a si ...
- hdu 1404 找sg ***
HDU 1404 Digital Deletions 一串由0~9组成的数字,可以进行两个操作:1.把其中一个数变为比它小的数:2.把其中一个数字0及其右边的所以数字删除. 两人轮流进行操作,最后把 ...