题目描述

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+y2​ .

Allen had a bit too much to drink at the bar, which is at the origin. There are n n n vectors v1⃗,v2⃗,⋯,vn⃗ \vec{v_1}, \vec{v_2}, \cdots, \vec{v_n} v1​​,v2​​,⋯,vn​​ . Allen will make n n n moves. As Allen's sense of direction is impaired, during the i i i -th move he will either move in the direction vi⃗ \vec{v_i} vi​​ or −vi⃗ -\vec{v_i} −vi​​ . In other words, if his position is currently p=(x,y) p = (x, y) p=(x,y) , he will either move to p+vi⃗ p + \vec{v_i} p+vi​​ or p−vi⃗ p - \vec{v_i} p−vi​​ .

Allen doesn't want to wander too far from home (which happens to also be the bar). You need to help him figure out a sequence of moves (a sequence of signs for the vectors) such that his final position p p p satisfies ∣p∣≤1.5⋅106 |p| \le 1.5 \cdot 10^6 ∣p∣≤1.5⋅106 so that he can stay safe.

输入输出格式

输入格式:

The first line contains a single integer n n n ( 1≤n≤105 1 \le n \le 10^5 1≤n≤105 ) — the number of moves.

Each of the following lines contains two space-separated integers xi x_i xi​ and yi y_i yi​ , meaning that vi⃗=(xi,yi) \vec{v_i} = (x_i, y_i) vi​​=(xi​,yi​) . We have that ∣vi∣≤106 |v_i| \le 10^6 ∣vi​∣≤106 for all i i i .

输出格式:

Output a single line containing n n n integers c1,c2,⋯,cn c_1, c_2, \cdots, c_n c1​,c2​,⋯,cn​ , each of which is either 1 1 1 or −1 -1 −1 . Your solution is correct if the value of p=∑i=1ncivi⃗ p = \sum_{i = 1}^n c_i \vec{v_i} p=∑i=1n​ci​vi​​ , satisfies ∣p∣≤1.5⋅106 |p| \le 1.5 \cdot 10^6 ∣p∣≤1.5⋅106 .

It can be shown that a solution always exists under the given constraints.

输入输出样例

输入样例#1:

  1. 3
  2. 999999 0
  3. 0 999999
  4. 999999 0
输出样例#1:

  1. 1 1 -1
输入样例#2:

  1. 1
  2. -824590 246031
输出样例#2:

  1. 1
输入样例#3:

  1. 8
  2. -67761 603277
  3. 640586 -396671
  4. 46147 -122580
  5. 569609 -2112
  6. 400 914208
  7. 131792 309779
  8. -850150 -486293
  9. 5272 721899
输出样例#3:

  1. 1 1 1 1 1 1 1 -1

Solution:

  本题很玄学,正解不会,直接随机。

  用random_shuffle去随机打乱数组,然后贪心,对于第$i$个向量直接在$+1,-1$中选一个使向量长度小的,然后判断向量和的长度是否满足条件就好了。

代码:

  1. #include<bits/stdc++.h>
  2. #define il inline
  3. #define ll long long
  4. #define For(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
  5. #define Bor(i,a,b) for(int (i)=(b);(i)>=(a);(i)--)
  6. using namespace std;
  7. const int N=;
  8. const ll T=*1ll*;
  9. ll ans[N];
  10. ll n;
  11. struct node{
  12. ll id,x,y;
  13. }a[N];
  14.  
  15. il int gi(){
  16. int a=;char x=getchar();bool f=;
  17. while((x<''||x>'')&&x!='-')x=getchar();
  18. if(x=='-')x=getchar(),f=;
  19. while(x>=''&&x<='')a=(a<<)+(a<<)+x-,x=getchar();
  20. return f?-a:a;
  21. }
  22.  
  23. il ll lala(ll x,ll y){return x*x+y*y;}
  24.  
  25. int main(){
  26. srand(time());
  27. n=gi();
  28. For(i,,n) a[i].x=gi(),a[i].y=gi(),a[i].id=i;
  29. ll x,y;
  30. while(){
  31. random_shuffle(a+,a+n+);
  32. x=,y=;
  33. For(i,,n)
  34. if(lala(x-a[i].x,y-a[i].y)<lala(a[i].x+x,a[i].y+y)) ans[a[i].id]=-,x-=a[i].x,y-=a[i].y;
  35. else ans[a[i].id]=,x+=a[i].x,y+=a[i].y;
  36. if(lala(x,y)<=T) {For(i,,n) printf("%lld ",ans[i]);break;}
  37. }
  38. return ;
  39. }
 

CF995C Leaving the Bar的更多相关文章

  1. Codeforces 996E Leaving the Bar (随机化)

    题目连接:Leaving the Bar 题意:给你n个向量,你可以加这个向量或减这个向量,使得这些向量之和的长度小于1.5e6. 题解: 按照正常的贪心方法,最后的结果有可能大于1.5e6 .这里我 ...

  2. 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 ...

  3. [Codeforces995C]Leaving the Bar 瞎搞

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

  4. 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)

    题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...

  5. ural 2013 Neither shaken nor stirred

    2013. Neither shaken nor stirred Time limit: 1.0 secondMemory limit: 64 MB The ACM ICPC regional con ...

  6. Customizing Navigation Bar and Status Bar

    Like many of you, I have been very busy upgrading my apps to make them fit for iOS 7. The latest ver ...

  7. Android设计和开发系列第二篇:Action Bar(Develop—API Guides)

    Action Bar IN THIS DOCUMENT Adding the Action Bar Removing the action bar Using a logo instead of an ...

  8. scala - multiple overloaded alternatives of method bar define default arguments

    同名同位置默认参数不能overload def bar(i:Int,s:String="a"){} def bar(i:String,s:String="b") ...

  9. 编程中Foo, Bar 到底什么意思?

    1 前言 在很多国外计算机书本和一些第三份开源软件的Demo中经常用到两个英文单词Foo,Bar.这到底是什么意思呢?从步入屌丝界的IT生活见到这两个单词到现在我还是不知道这两个单词的真正含义,今天有 ...

随机推荐

  1. 优步UBER司机全国各地奖励政策汇总 (2月29日-3月6日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  2. EF Core ThenInclude 2.0自动完成提示有误,坑了一下

    只要代码正确,可以编译运行的... https://github.com/dotnet/roslyn/issues/8237

  3. JAVA日志框架概述

            日志用来记录应用的运行状态以及一些关键业务信息,其重要性不言而喻,通常我们借助于现有的日志框架完成日志输出.目前开源的日志框架很多,常见的有log4j.logback等,有时候我们还会 ...

  4. Qt-QML-C++交互实现文件IO系统

    QMl是没有自己的文件IO控制的,这里如果我们需要对文件进行读写操作,那么就需要去C++或者JS完成交互,交互方式有多种,由于我还没有掌握,这里就不介绍具体的交互方式了.这里就简单说明一下我的实现过程 ...

  5. XSS----payload,绕过,xss小游戏记录

    一.XSS 1.原理:攻击者把恶意的脚本代码注入到网页中,等待其他用户浏览 这些网页(或触发其他条件),从而执行其中的恶意代码. 1.xss实例代码: test.html <!DOCTYPE h ...

  6. Unity 编辑器扩展

    自定义检视面板的使用: 先是定义一个脚本文件,我们来修饰它的检视面板: [HelpURL("http://www.baidu.com")] public class Atr : M ...

  7. ArcFaceDemo 第二版【C#】——视频人脸识别

    啥话不说,不用跪求,直接给下载地址:http://common.tenzont.com/comdll/arcface2demo.zip(话说附件的大小不限制,还是说我的文件太大,实际上确实有点大,60 ...

  8. 机器学习实战笔记一:K-近邻算法在约会网站上的应用

    K-近邻算法概述 简单的说,K-近邻算法采用不同特征值之间的距离方法进行分类 K-近邻算法 优点:精度高.对异常值不敏感.无数据输入假定. 缺点:计算复杂度高.空间复杂度高. 适用范围:数值型和标称型 ...

  9. STM32F4编程手册学习2_内存模型

    STM32F4编程手册学习2_内存模型 1. 内存映射 MCU将资源映射到一段固定的4GB可寻址内存上,如下图所示. 内存映射将内存分为几块区域,每一块区域都有一个定义的内存类型,一些区域还有一些附加 ...

  10. mac上golang编译出现clang错误

    错误现象 几周前,突然发现我的go 项目编译开始报一种以前从来没有出现过的错误: # runtime/cgo clang: warning: argument unused during compil ...