Family Gathering at Christmas(思维题)
Family Gathering at Christmas
时间限制: 1 Sec 内存限制: 128 MB
提交: 13 解决: 4
[提交] [状态] [讨论版] [命题人:admin]
题目描述
Alice suggests a way for her family to determine the gathering place. First, she associates each member with a weight, which quantifies the way of transportation. Then, the time needed for each non-host member m to reach the host is
where wm is the weight of the member, d m is the distance from the member’s place to the central city, and d h is the distance from the central city to the host’s place. Then she associates each member’s place with a key, which is the longest time needed for a non-host member to reach the place. To decide the host, she picks a small number k, and choose a place with the kth smallest key. Please develop an efficient algorithm to help Alice find the kth smallest key.
输入
The second line contains n integers, w1 , . . . , wn , and the third line contains d1 , . . . , dn . Two consecutive integers in a line are separated by a space.
输出
样例输入
2
3 2
5 3 4
3 8 5
4 2
6 2 8 2
10 18 12 4
样例输出
40
132
有的人用线段树做的,懂不起!
AC代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef struct{
int su,wei;
}my;
int n,k;
my f[];
int comp(my x,my y)
{
if(x.wei<y.wei)
return ;
return ;
}
long long ans1,ans2,ans3,num,maxn,minn;
int t1;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++)
scanf("%d",&f[i].su);
for(int i=;i<=n;i++)
scanf("%d",&f[i].wei);
sort(f+,f+n+,comp);
ans1=,t1=;
for(int i=;i<=n;i++)
if(i!=k)
{
if(ans1<1LL*f[i].su*(f[i].wei+f[k].wei))
ans1=1LL*f[i].su*(f[i].wei+f[k].wei),t1=i;
}
if(t1>k)
{
ans2=;
for(int i=;i<=n;i++)
if(i!=t1)
{
if(ans2<1LL*f[i].su*(f[i].wei+f[t1].wei))
ans2=1LL*f[i].su*(f[i].wei+f[t1].wei);
}
}
else
{
ans2=5000000000LL;
}
if(k==)
{
ans3=;
}
else
{
ans3=;
for(int i=;i<=n;i++)
if(i!=k-)
{
if(ans3<1LL*f[i].su*(f[i].wei+f[k-].wei))
ans3=1LL*f[i].su*(f[i].wei+f[k-].wei);
}
}
num=ans1+ans2+ans3;
minn=min(ans1,min(ans2,ans3));
maxn=max(ans1,max(ans2,ans3));
printf("%lld\n",num-minn-maxn);
}
return ;
}
Family Gathering at Christmas(思维题)的更多相关文章
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- cf A. Inna and Pink Pony(思维题)
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)
思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记
PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...
- UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)
UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...
- HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)
HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...
- cf796c 树形,思维题
一开始以为是个树形dp,特地去学了..结果是个思维题 /* 树结构,设最大点权值为Max,则答案必在在区间[Max,Max+2] 证明ans <= Max+2 任取一个点作为根节点,那么去掉这个 ...
随机推荐
- Autel MaxiSys MS908CV Diagnostic System for Commercial Vehicles
As a new member of Autel’s MaxiSys family, the MaxiSys CV is built on the powerful MaxiSys 908 platf ...
- php数组·的方法1-数组的操作
//range() 创建一个含指定范围的数组 可设置间隔 var_dump(range(1, 9, 2)); echo '<br>'; //array_combine() 合并两个数组创建 ...
- my.宠物价格_资料
1.梦幻西游手游宠物估价五大实用技巧_72G梦幻西游手游专区.html http://www.72g.com/game/mhxysy/88470.html 梦幻西游手游宠物估价五大实用技巧 作者:升仙 ...
- Hidden Markov Models笔记
Andrew Ng CS229 讲义: https://pan.baidu.com/s/12zMYBY1NLzkluHNeMNO6MQ HMM模型常用于NLP.语音等领域. 马尔科夫模型(Markov ...
- C++学习笔记:
一 友元函数:友元函数没有this指针,不是类的成员,在外部定义无需类标识符,引用全局或者静态对象不需要类对象标识符,而访问非静态对象则需要. 二 类继承:如果不指定继承方式,默认是私有继承.但私有继 ...
- 3d Max 2015安装失败怎样卸载3dsmax?错误提示某些产品无法安装
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- MAYA删除不干净
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- EOF是什么
我学习C语言的时候,遇到的一个问题就是EOF. 它是end of file的缩写,表示"文字流"(stream)的结尾.这里的"文字流",可以是文件(file) ...
- [转]jquery插件创建 jquery.fn.extend与jquery.extend
本文转自:http://www.cnblogs.com/wyjgreat/archive/2011/07/19/2110754.html jQuery为开发插件提拱了两个方法,分别是: JavaScr ...
- Castle.DynamicProxy的使用
.Net平台AOP技术研究 简单实现 通过继承实现 public interface ICoding { void DoSth(); } public class Coding : ICoding { ...