题目连接:Leaving the Bar

题意:给你n个向量,你可以加这个向量或减这个向量,使得这些向量之和的长度小于1.5e6。

题解: 按照正常的贪心方法,最后的结果有可能大于1.5e6 。这里我们可以加一些随机性,多次贪心,直到结果满足题意。正解是每三个向量中都能找到两个向量合起来 <= 1e6,然后不断合并,最后只会剩下一个或者两个向量,如果一个向量肯定 <= 1e6, 如果是两个向量一定 <= 1.5 * 1e6。这是我第一遇到随机化的题~~~

 #include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;
const int MAX_N =1e5+;
int N,M,T,S;
struct node{
int f,s,v;
};
node vec[MAX_N];
int res[MAX_N];
int main()
{
while(cin>>N){
for(int i=;i<N;i++){
scanf("%d%d",&vec[i].f,&vec[i].s);
vec[i].v = i;
}
LL ti = ;
while(){
LL x = ;
LL y = ;
for(int i=;i<N;i++){
if((x + vec[i].f)*(x+vec[i].f) + (y+vec[i].s)*(y+vec[i].s) <=
(x - vec[i].f)*(x-vec[i].f) + (y-vec[i].s)*(y-vec[i].s) ){
x += vec[i].f;
y += vec[i].s;
res[vec[i].v] = ;
}
else{
x -= vec[i].f;
y -= vec[i].s;
res[vec[i].v] = -;
}
}
if(x*x+y*y <= ti*ti){
for(int i=;i<N;i++){
printf("%d ",res[i]);
}
cout<<endl;
break;
}
random_shuffle(vec, vec+N);
}
}
return ;
}

Codeforces 996E Leaving the Bar (随机化)的更多相关文章

  1. Codeforces 749D. Leaving Auction set+二分

    D. Leaving Auction time limit per test: 2 seconds memory limit per test:256 megabytes input:standard ...

  2. Codeforces Problem 598E - Chocolate Bar

    Chocolate Bar 题意: 有一个n*m(1<= n,m<=30)的矩形巧克力,每次能横向或者是纵向切,且每次切的花费为所切边长的平方,问你最后得到k个单位巧克力( k <= ...

  3. CF995C Leaving the Bar

    题目描述 For a vector v⃗=(x,y) \vec{v} = (x, y) v=(x,y) , define ∣v∣=x2+y2 |v| = \sqrt{x^2 + y^2} ∣v∣=x2 ...

  4. codeforces 598E E. Chocolate Bar(区间dp)

    题目链接: E. Chocolate Bar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  5. CodeForcesdiv1:995C - Leaving the Bar(随机算法+贪心)

    For a vector →v=(x,y)v→=(x,y), define |v|=√x2+y2|v|=x2+y2. Allen had a bit too much to drink at the ...

  6. codeforces 749D Leaving Auction(二分)

    题目链接:http://codeforces.com/problemset/problem/749/D 题意:就是类似竞拍,然后报价肯定要比上一个高,然后查询输入k个数表示那些人的竞拍无效, 输出最后 ...

  7. Codeforces 598E:Chocolate Bar

    E. Chocolate Bar time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  8. CodeForces 749D Leaving Auction

    二分查找,$set$. 对于某一次询问,如果把人删光了,那么输出$0$ $0$. 如果只剩下$1$个人,那么输出那个人喊的最低价格. 如果剩下的人数有大于等于两个, 这时最底下出现的情景必然是红色部分 ...

  9. [Codeforces995C]Leaving the Bar 瞎搞

    大致题意: 给出平面上n个向量,对于每个向量可以选择正的V或负的-V,求按照选择的向量走完,最后距离原点<=1.5*1e6的一个选择方案 非正解!!!!!!!!!! 先按距离原点距离由远到近贪心 ...

随机推荐

  1. python同步原语--线程锁

    多线程锁是python多种同步原语中的其中一种.首先解析一下什么是同步原语,python因为GIL(全局解析锁)的缘故,并没有真正的多线性.另外python的多线程存在一个问题,在多线程编程时,会出现 ...

  2. Spring Boot Actuator认识

    概述 spring-boot-starter-actuator:是一个用于暴露自身信息的模块,主要用于监控与管理. 为了保证actuator暴露的监控接口的安全性,需要添加安全控制的依赖spring- ...

  3. [20180604]在内存修改数据(bbed).txt

    [20180604]在内存修改数据(bbed).txt --//以前曾经做过在内存修改数据,通过oradebug poke命令修改内存信息,相关链接:--//http://blog.itpub.net ...

  4. [20171124]手工使用Seed_Database.dfb和Seed_Database.ctl建库.txt

    [20171124]手工使用Seed_Database.dfb和Seed_Database.ctl建库.txt --//昨天看yueli34的帖子,链接http://www.itpub.net/thr ...

  5. IDisposable

    自己备用 public static class PHDApi : IDisposable { private PHDAccess _phd = null; // Track whether Disp ...

  6. SELinux 是什么?

    一.SELinux的历史 SELinux全称是Security Enhanced Linux,由美国国家安全部(National Security Agency)领导开发的GPL项目,它拥有一个灵活而 ...

  7. Mongo学习---mongo入门1

    Docker安装以及设置mongo用户 docker pull mongo (拉取镜像 默认最新版本) docker images (查看镜像) docker run -p 27017:27017 - ...

  8. CentOS7查询系统版本内核信息

    1. 查看版本号 查看CentOS的版本号命令: [root@localhost ~]# cat /etc/centos-releaseCentOS Linux release 7.4.1708 (C ...

  9. 14LaTeX学习系列之---LaTeX的浮动体

    目录 目录 前言 (一)浮动体的基础知识 1.环境及语法 2.允许位置的参数 3.其他命令 (二)实例: 1.源代码 2.输出效果 (三)浮动体的高级操作 1.标题的控制 2.并排与子图表 3.绕排 ...

  10. nginx代理 upstream轮询

    问题描述 我有2个Tomcat  一个端口开启(8021),一个端口未开启(8022),在nginx里用upstream模块进行代理 ,代理的负载算法采用的是默认的轮询算法,配置成功后,访问页面时并没 ...