题目连接: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. Google Chrome 下载&绿化&增强

    Chrome下载 Google Chrome 已经可以在线更新,虽然比较慢! 国内常用的更新地址有两处:chromedownloads 和 shuax(耍下): https://www.chromed ...

  2. React JS和React-Native学习指南

    自己在学习React-Native过程中整理的一份学习指南,包含 教程.开源app和资源网站等,还在不断更新中.欢迎pull requests! React-Native学习指南本指南汇集React- ...

  3. log4net 写入日志到不同的位置

    某些业务需要根据不同的功能将日志记录到不同的位置,以便于区分. <?xml version="1.0" encoding="utf-8" ?> &l ...

  4. sql 删除默认索引,对象 依赖于 列,由于一个或多个对象访问此列

    declare @name varchar(50)select  @name =b.name from sysobjects b join syscolumns aon b.id = a.cdefau ...

  5. Arch Linux 更新源(以清华 arch 源为例)

    Arch Linux 编辑­/etc/pacman.d/mirrorlist,在文件最顶端添加: Server = https://mirrors.tuna.tsinghua.edu.cn/archl ...

  6. oh-my-zsh安装与使用

    使用oh-my-zsh之前确保安装过zsh 通过脚本安装: sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussel ...

  7. k8s调度的亲和性和反亲和性

    文章转自 http://ju.outofmemory.cn/entry/278349 https://www.jianshu.com/p/102c4df69af9 RequiredDuringSche ...

  8. linux终端神器kmux

    文章链接 https://www.cnblogs.com/rond/p/4466599.html http://cenalulu.github.io/linux/tmux/ https://www.c ...

  9. oracle(sql)基础篇系列(五)——PLSQL、游标、存储过程、触发器

    PL/SQL PL/SQL 简介 每一种数据库都有这样的一种语言,PL/SQL 是在Oracle里面的一种编程语言,在Oracle内部使用的编程语言.我们知道SQL语言是没有分支和循环的,而PL语言是 ...

  10. 导入其他python文件或者python文件的函数

    from abc import xxx 从abc的py文件导入一个具体的函数或者类 import abc 直接导入文件 a.b写在同一个文件目录下,a要使用b,直接import就可以了