大致题意:

  给出平面上n个向量,对于每个向量可以选择正的V或负的-V,求按照选择的向量走完,最后距离原点<=1.5*1e6的一个选择方案

  非正解!!!!!!!!!!

  先按距离原点距离由远到近贪心,贪完后答案若不满足,则进行一次dfs找出正确地路线即可(数据较水)

  也可以每次每次讲向量随机排序然后贪心,直到贪到正确答案为止。

  

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<cstdlib>
#include<cmath>
#include<list>
using namespace std;
#define MAXN 100100
#define eps 1e-9
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fre freopen
#define pi acos(-1.0)
#define inf 1e6+7
#define Vector Point
const int Mod=1e9+;
typedef unsigned long long ull;
typedef long long ll;
int dcmp(double x){
if(fabs(x)<=eps) return ;
return x<?-:;
}
struct Point{
double x,y;
int id;
Point(double x=,double y=):x(x),y(y) {}
bool operator < (const Point &a)const{
if(x==a.x) return y<a.y;
return x<a.x;
}
Point operator - (const Point &a)const{
return Point(x-a.x,y-a.y);
}
Point operator + (const Point &a)const{
return Point(x+a.x,y+a.y);
}
Point operator * (const double &a)const{
return Point(x*a,y*a);
}
Point operator / (const double &a)const{
return Point(x/a,y/a);
}
void read(){
scanf("%lf%lf",&x,&y);
}
void out(){
cout<<"debug: "<<x<<" "<<y<<endl;
}
bool operator == (const Point &a)const{
return dcmp(x-a.x)== && dcmp(y-a.y)==;
}
};
double Dot(Vector a,Vector b) {
return a.x*b.x+a.y*b.y;
}
double dis(Vector a) {
return sqrt(Dot(a,a));
}
double Cross(Point a,Point b){
return a.x*b.y-a.y*b.x;
}
int Maxx=;
bool cmp(Point a,Point b){
return dcmp(dis(a)-dis(b))>;
}
bool check(Point o,Point p1){
return dcmp(dis(o+p1)-dis(o-p1))<=;
}
int ans[];
Point p[];
int n,mk;
void dfs(int now,Point o){
if(mk) return ;
if(now==n) {
if(dcmp(dis(o)-Maxx)>) return ;
mk=;
For(i,,n-) {
if(i) printf(" ");
printf("%d",ans[i]);
}
cout<<endl;
return ;
}
ans[p[now].id]=;
dfs(now+,o+p[now]);
ans[p[now].id]=-;
dfs(now+,o-p[now]);
}
void solve(){
cin>>n;
For(i,,n-) p[i].read(),p[i].id=i;
mk=;
sort(p,p+n,cmp);
Point o(,);
For(i,,n-){
if(check(o,p[i])) ans[p[i].id]=,o=o+p[i];
else ans[p[i].id]=-,o=o-p[i];
}
if(dcmp(dis(o)-Maxx)<=) {
For(i,,n-){
if(i) printf(" ");
printf("%d",ans[i]);
}
cout<<endl;
return ;
}
dfs(,Point(,));
}
int main(){
// fre("in.txt","r",stdin);
int t=;
solve();
return ;
}

贪心+dfs

[Codeforces995C]Leaving the Bar 瞎搞的更多相关文章

  1. URAL 1203. Scientific Conference(瞎搞)

    题目链接 本来觉得这不是经典的贪心吗..果断水一次,wa了,看了看discuss,发现貌似不好水,土土的DP了一下,复杂度很高了,又T了...然后想想单调队列,二分什么的...不好往上加,直接搞了标记 ...

  2. Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞

    Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...

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

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

  4. B. Salty Fish Go! -期望题(瞎搞题)

    链接:https://www.nowcoder.com/acm/contest/104/B来源:牛客网 题意:A few days ago, WRD was playing a small game ...

  5. HDU5532 Almost Sorted Array(最长上升子序列 or 瞎搞个做差的数组)

    题目链接:点我 题意:给定一个序列,询问是否能删除一个数让它成为非递减或者非递增的序列. 比如说 删除后的序列是1 3 3 5 或者5 3 3 1 或者1 3 5 或者5 3 1 都可以.只要满足删掉 ...

  6. TOJ3097: 单词后缀 (字典树 or map瞎搞)

    传送门 (<---可以点击的~) 时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte 描述 有些英语单词后缀都是一样的,现在我们需要从给定的一堆单词里 ...

  7. 8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞

    B. Cards 题目连接: http://www.codeforces.com/contest/626/problem/B Description Catherine has a deck of n ...

  8. ubuntu--基础环境瞎搞集合

    安装ubuntu系统后有很多东西需要自己瞎搞一下,这里把一些瞎搞的过程记录在这里,方便以后重新装系统后重新配置. 一.安装. 可以在windows下制作启动盘(软碟通),然后开机u盘启动即可安装,预留 ...

  9. Codeforces631C【栈维护+瞎搞】

    题意: 百度. 思路: 如果该查询的R比前面的所有都大,那么前面所有都失效. 那么我先预处理出这些有效的. 那最坏的情况不就是栈里面元素(R)很多 n,n-1,n-2,n-3,n-4而且都是相反排序的 ...

随机推荐

  1. Jquery validate验证表单时多个name相同的元素只验证第一个的问题

    下面搜集了五种方法,主要还是前两个提供了解决方案,第三种需要修改jQuery源码: 修复jquery.validate插件中name属性相同(如name='a[]')时验证的bug 使用jquery. ...

  2. POJ 3348 Cows 凸包 求面积

    LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...

  3. Linux网络知识

    在思科上面模拟一下数据包的传递过程:一般上网使用的协议是tcp 交换机是一个2层的设备,它和Ip地址是没有关系的. 交换机上主要处理的是硬件地址(MAC),它只能分析到硬件地址,再到IP地址它就不管了 ...

  4. JavaScript-变量与作用域链

    jQuery片段:  1 var 2     // Will speed up references to window, and allows munging its name. 3     win ...

  5. 源自人脑的神奇算法 -- 读《How to make your own neural network》有感

    最近读到了一本很好的关于机器学习-深度学习的书值得推荐下并特意做了这个学习总结. 为什么推荐 在我认为好书(计算机类)的评判有几个标准: 试图以通俗的语言阐述,并在引入任何新概念的时候都讲述来龙去脉, ...

  6. arguments.length

    本文地址:http://www.cnblogs.com/veinyin/p/7607083.html  arguments.length是实参的个数,与形参个数无关.

  7. 【leetcode 简单】第十四题 最后一个单词的长度

    给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度. 如果不存在最后一个单词,请返回 0 . 说明:一个单词是指由字母组成,但不包含任何空格的字符串. 示例: 输入: &quo ...

  8. Shodan 使用

    本文来自:Shodan新手入坑指南, 记录简要用法,以便使用. 文章先给出搜索过滤方法,然后再简单介绍两种使用shodan的方法:使用命令和编写代码. 搜索过滤 hostname:搜索指定的主机或域名 ...

  9. 2017ACM暑期多校联合训练 - Team 7 1009 HDU 6128 Inverse of sum (数学计算)

    题目链接 Problem Description There are n nonnegative integers a1-n which are less than p. HazelFan wants ...

  10. input只读属性readonly和disabled的区别

    主要区别: 参考: http://bbs.html5cn.org/forum.php?mod=viewthread&tid=84113&highlight=input http://b ...