URAL - 1397:Points Game (博弈,贪心)
Input
Output
Example
| input | output |
|---|---|
2 |
0.000 |
思路:之前遇到了类似的题。由于这样的题比较抽象,当时我是陷入了矛盾的,A既要让自己越大越好,又要使B越小越好(B同理),这两个标准会不会又矛盾呢,该遵循哪一个呢。
此题可以推出来,二则在使自己大的时候,也约束 了对方更小。
val A= Sum( distant(pi,pj) ) { i<j && i,j belong to A} - Sum( distant(pi,pj) ) {i<j && i,j belong to B}
= Sum( distant(pi,pj) ) {i,j belong to Q} - Sum( distant(pi,pj) ) { i belong to B && j belong to Q}
(其中Q是全集。
我们令dis是点到其他所有点的距离之和,那么A和B都按照dis从大到小选,既能要自己更大,也能让对方更小。
(下次再遇到这样的题,就用公式,把他们的标准统一就好了(如果可以的话)。
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
double x[maxn],y[maxn],dis[maxn],ans;int p[maxn];
bool cmp(int w,int v){ return dis[w]>dis[v]; }
double dist(int u,int v){
return sqrt((x[u]-x[v])*(x[u]-x[v])+(y[u]-y[v])*(y[u]-y[v]));
}
int main()
{
int N;
while(scanf("%d",&N)==){ N<<=;
for(int i=;i<=N;i++) scanf("%lf%lf",&x[i],&y[i]);
for(int i=;i<=N;i++) p[i]=i;
for(int i=;i<=N;i++){
dis[i]=.;
for(int j=;j<=N;j++) dis[i]+=dist(i,j);
}
sort(p+,p+N+,cmp); ans=;
for(int i=;i<=N;i++){
double tmp=0.0;
for(int j=i+;j<=N;j+=) tmp+=dist(p[i],p[j]);
if(i&) ans+=tmp; else ans-=tmp;
}
printf("%.3lf\n",ans);
}
return ;
}
URAL - 1397:Points Game (博弈,贪心)的更多相关文章
- ural 1303 Minimal Coverage【贪心】
链接: http://acm.timus.ru/problem.aspx?space=1&num=1303 http://acm.hust.edu.cn/vjudge/contest/view ...
- HDU 4023 (博弈 贪心 模拟) Game
如果硬要说这算是博弈题目的话,那这个博弈是不公平博弈(partizan games),因为双方面对同一个局面做出来的决策是不一样的. 我们平时做的博弈都是公平博弈(impartial games),所 ...
- Codeforces C Match Points(二分贪心)
题目描述: Match Points time limit per test 2 seconds memory limit per test 256 mega bytes input standard ...
- POJ 2505 A multiplication game(找规律博弈/贪心)
题目链接 #include<iostream> #include<cstdio> using namespace std; typedef long long ll; int ...
- URAL 1203 Scientific Conference(贪心 || DP)
Scientific Conference 之前一直在刷计算几何,邀请赛连计算几何的毛都买见着,暑假这一段时间就做多校.补多校的题目.刷一下一直薄弱的DP.多校假设有计算几何一定要干掉-.- 题意:给 ...
- ural 2021 Scarily interesting!(贪心)
2021. Scarily interesting! Time limit: 1.0 secondMemory limit: 64 MB This year at Monsters Universit ...
- Ural 1303 Minimal Coverage(贪心)
题目地址:Ural 1303 先按每一个线段的左端点排序,然后设置一个起点s.每次都从起点小于等于s的线段中找到一个右端点最大的. 并将该右端点作为新的起点s,然后继续找. 从左到右扫描一遍就可以. ...
- URAL 1161 Stripies(数学+贪心)
Our chemical biologists have invented a new very useful form of life called stripies (in fact, they ...
- URAL 1303 Minimal Coverage
URAL 1303 思路: dp+贪心,然后记录路径 mx[i]表示从i开始最大可以到的位置 sufmx[i]表从1-i的某个位置开始最大可以到达的位置 比普通的贪心效率要高很多 代码: #inclu ...
随机推荐
- Codeforces 735B - Urbanization
735B - Urbanization 思路:贪心.人数少的城市住钱最多的那几个人. 不证明了,举个例子吧:a1<a2<a3<a4<a5 (a1+a2+a3)/3+(a4+a5 ...
- C#将集合和Json格式互相转换的几种方式
1.使用微软自带的System.Web.Extensions.dll转换,该DLL文件一般存在于如下路径:c:\Program Files\Reference Assemblies\Microsoft ...
- spring boot: GlobalDefaultExceptionHandler方法内的友好错误提示,全局异常捕获
spring boot: GlobalDefaultExceptionHandler方法内的友好错误提示,全局异常捕获 当你的某个控制器内的某个方法报错,基本上回显示出java错误代码,非常不友好,这 ...
- python-day9-集合数据类型
pythons=['alex','egon','yuanhao','wupeiqi','gangdan','biubiu']linuxs=['wupeiqi','oldboy','gangdan'] ...
- mysql导入导出数据过大命令
phpmyadmin 导入或者导出都是有限制的,当导入或者导出的数据会报错. 1.导入数据库 mysql -u root -p<备份文件的保存路径 eg: mysql -u root -p &l ...
- 弗洛伊德算法(Floyd算法)
原博来自http://www.cnblogs.com/skywang12345/ 弗洛伊德算法介绍 和Dijkstra算法一样,弗洛伊德(Floyd)算法也是一种用于寻找给定的加权图中顶点间最短路径的 ...
- 连接ACCESS
access2000-2003数据库连接字符串: ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据库名.mdb"; ...
- 修改XML的节点内容
这种形式可以修改任何一个节点: XmlDocument doc = new XmlDocument(); doc.Load("Event.xml"); XmlElement eve ...
- 在命令行中直接运行带main方法的java
用了很久的java,基本都是交给服务器完成的执行,有page之类的入口,或者是在IDE工具中直接 Run As Java Application. 并且一直对安装java之后配置JAVA_HOME,p ...
- 10. Regular Expression Matching *HARD*
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...