Ural 1397. Points Game
来源:互联网 发布:传智播客php笔记 编辑:程序博客网 时间:2024/06/06 02:15
Ural 1397. Points Game
假设玩家A取的石子集合是A,B的是B
val = 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}
我们记录每个石子到其他石子的距离的总和,然后排序。
这样的方法就是贪心取。。
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<set>#include<queue>#include<map>#include<sstream>#include<iostream>using namespace std;#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)#define bug puts("Fuck");#define LL long long#define pb push_back#define mp make_pair#define nMax 1010#define eps 1e-8#define inf 0x7fffffffdouble dir(double x) { return x*x; }class P{public:double x,y;void read() { scanf("%lf%lf",&x,&y);};double dis(P b) {return sqrt(dir(x-b.x) + dir(y-b.y));}};P p[nMax];int n;int input() {if(scanf("%d",&n)==EOF) return 0;for(int i=0;i<2*n;i++) p[i].read();n <<= 1;return 1;}double sum[nMax];void sovle(){double total=0.0;for(int i=0;i<n;i++) {sum[i] = 0;for(int j=0;j<n;j++) sum[i] += p[i].dis(p[j]);total += sum[i];}total /= 2;sort(sum,sum+n);for(int i=0;i<n;i+=2) total -= sum[i];printf("%.3lf\n",total+1e-9);}int main(){#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);#endifwhile(input())sovle();return 0;}
- Ural 1397. Points Game
- URAL 1397 Points Game <博弈>
- ural 1060 Flip Game
- URAL 1465 Pawn Game
- Ural 1180. Stone Game
- Ural 1180 Stone Game
- Ural 1060. Flip Game
- Ural 1282. Game Tree
- Ural 1465 Pawn Game
- URAL 1976 Game Optimization
- URAL 1122 Game
- URAL 1282 Game Tree
- URAL 1180 Stone Game
- a small game-21 points
- URAL 1489. Points on a Parallelepiped
- URAL 1489 Points on a Parallelepiped
- URAL 1382 Game with Cards
- Ural 1060. Flip Game dfs
- build/core/base_rules.mk:195: already define
- URAL 1635
- 分类算法之决策树
- Linux内核高端内存
- asp.net WebForm程序删除.designer.cs文件,重新设计并绑定服务端控件时间
- Ural 1397. Points Game
- js等比缩放图片
- 未完成的旅行商问题
- 通配符是什么
- linux 编译系统的简单介绍与内核编译与安装
- Linux解决Device eth0 does not seem to be present
- 微信公众帐号开发教程第1篇-引言
- 自旋锁 Spin Lock
- poj 3420 dp+矩阵(矩形填充)