poj 1701 Dissatisfying Lift (枚举)
来源:互联网 发布:淘宝公益宝贝哪儿看 编辑:程序博客网 时间:2024/05/04 00:01
Dissatisfying Lift
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 5102 Accepted: 1123
Description
There's a building with M floors. The amounts of tenants of every floor are K1, K2, K3, ..., Km. One day all the tenants went home together and they took the same lift (suppose the lift was large enough). Because of some reason the lift could only stop on one floor and the tenants must go upstairs or downstairs to their houses. Every tenant went up N floors would make the dissatisfied degree rise N * a + 0.5 * N * (N - 1) degrees, and every tenant went down N floors would make the dissatisfied degree rise N * b + 0.5 * N * (N - 1) degrees. Your task is to tell which floor the lift should stop, in order to make the dissatisfied degree as low as possible.
Input
The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. The first line of each test contains M (1 <= M <= 10000), a and b (0 <= a, b <= 100). The second line contains K1, K2, K3, ..., Km (0 <= Ki <= 20, i = 1..M).
Output
For each test case, print a line containing a single integer, indicating which floor the lift should stop.
Sample Input
15 3 21 1 1 1 1
Sample Output
3
分析:则任意求任意两层不满衣服只差的最小值即为所要求的楼层。
dD(i+1,i)=Di+1 - Di;
花间得dD=(b+i)*sumk[i] - (a-i-1)*(sumk[M]-sumk[i])-c;#include <iostream>using namespace std;int T,M,a,b;int k[10010],sumk[10010];long long dD; //dD=在第i+1层停靠的不满意度之和与在i层不满意度之和的差long long c; //c=k[1]*1+k[2]*2+k[3]*3+....+k[m]*m;int ans;int main(){ int i; cin>>T; while(T--) { cin>>M>>a>>b; //楼层数 上满意度 下满意度 cin>>k[1];c=sumk[1]=k[1]; for(i=2;i<=M;i++) { cin>>k[i]; sumk[i] = sumk[i-1]+k[i]; c+=k[i]*i; } //求解并输出 ans=1; for(i=1;i<M;i++) { dD=(b+i)*sumk[i] - (a-i-1)*(sumk[M]-sumk[i])-c; if(dD<0) ans=i+1; else break; } cout<<ans<<endl; } return 0;}
- poj 1701 Dissatisfying Lift (枚举)
- POJ 1701 Dissatisfying Lift
- poj 1701 dissatisfying lift
- poj 1701 Dissatisfying Lift
- POJ 1701 Dissatisfying Lift 笔记
- Dissatisfying Lift
- POJ 1548 A strange lift(BFS)
- POJ 1062 枚举+dijkstra()
- POJ 2965(DFS+枚举)
- POJ 1046 (枚举,类)
- poj 3671(暴力 枚举)
- POJ 3977(枚举+二分)
- POJ 3279 (枚举+二进制)
- poj 3295 Tautology(枚举)
- Tautology(POJ 3295)(暴力枚举)
- poj Flip Game(DFS)(枚举)
- poj 1753 Flip Game(dfs+枚举)
- poj 3189(枚举+最大流)
- 3520a SDL_tff库做bmp 也就是osd
- 稳定,快速的xmonad
- vi 的经典命令防遗忘
- HDU 1050 Moving Tables (贪心 区间最大叠加数)
- ant学习笔记(六)ant编译web项目,并打成war包,同时加入数据库操作
- poj 1701 Dissatisfying Lift (枚举)
- 观察者模式
- 深入研究数据访问:什么是SQL注入
- 其他优化技巧
- c++ 关联容器详解——从内部结构到应用
- Java Map 按Key排序和按Value排序
- json数据格式
- Android中状态栏的隐藏
- How to select unique records by SQL