[Codeforces995C]Leaving the Bar 瞎搞
大致题意:
给出平面上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 瞎搞的更多相关文章
- URAL 1203. Scientific Conference(瞎搞)
题目链接 本来觉得这不是经典的贪心吗..果断水一次,wa了,看了看discuss,发现貌似不好水,土土的DP了一下,复杂度很高了,又T了...然后想想单调队列,二分什么的...不好往上加,直接搞了标记 ...
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...
- Codeforces 996E Leaving the Bar (随机化)
题目连接:Leaving the Bar 题意:给你n个向量,你可以加这个向量或减这个向量,使得这些向量之和的长度小于1.5e6. 题解: 按照正常的贪心方法,最后的结果有可能大于1.5e6 .这里我 ...
- B. Salty Fish Go! -期望题(瞎搞题)
链接:https://www.nowcoder.com/acm/contest/104/B来源:牛客网 题意:A few days ago, WRD was playing a small game ...
- HDU5532 Almost Sorted Array(最长上升子序列 or 瞎搞个做差的数组)
题目链接:点我 题意:给定一个序列,询问是否能删除一个数让它成为非递减或者非递增的序列. 比如说 删除后的序列是1 3 3 5 或者5 3 3 1 或者1 3 5 或者5 3 1 都可以.只要满足删掉 ...
- TOJ3097: 单词后缀 (字典树 or map瞎搞)
传送门 (<---可以点击的~) 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 描述 有些英语单词后缀都是一样的,现在我们需要从给定的一堆单词里 ...
- 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 ...
- ubuntu--基础环境瞎搞集合
安装ubuntu系统后有很多东西需要自己瞎搞一下,这里把一些瞎搞的过程记录在这里,方便以后重新装系统后重新配置. 一.安装. 可以在windows下制作启动盘(软碟通),然后开机u盘启动即可安装,预留 ...
- Codeforces631C【栈维护+瞎搞】
题意: 百度. 思路: 如果该查询的R比前面的所有都大,那么前面所有都失效. 那么我先预处理出这些有效的. 那最坏的情况不就是栈里面元素(R)很多 n,n-1,n-2,n-3,n-4而且都是相反排序的 ...
随机推荐
- Codeforces 221 A. Little Elephant and Function
A. Little Elephant and Function time limit per test 2 seconds memory limit per test 256 megabytes in ...
- 搭建简单的node+express+mongodb项目
安装 首先要确保已经安装了 Node.js,接下来创建一个目录,然后进入此目录并将其作为当前工作目录. mkdir myapp cd myapp 通过 npm init 命令为应用创建一个 packa ...
- 【POJ】3233 Matrix Power Series
[算法]二分+矩阵快速幂 [题意]给定矩阵A和整数k,MOD,求A^0+A^1+A^2+...+A^k. [题解] 定义题目要求的答案为f(n),即: $$f_n=\sum_{i=0}^{n}A^i$ ...
- 【Atcoder】AGC022 C - Remainder Game 搜索
[题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...
- H5小游戏——看你有多色
使用了封装了canvas的create.js库来实现的. 最终效果: 工程: Rect.js /* * 方块类 */ function Rect(n,color,specialColor){ crea ...
- 可怕的npm蠕虫
https://hackernoon.com/im-harvesting-credit-card-numbers-and-passwords-from-your-site-here-s-how-9a8 ...
- css_input[checked]复选框去掉默认样式并添加新样式
效果对比: “\2713”实体符号√ :如有兴趣查看详细实体符号请点这里 代码实现: <!DOCTYPE html> <html> <head> <meta ...
- Lucene7.2.1系列(三)查询及高亮
系列文章: Lucene系列(一)快速入门 Lucene系列(二)luke使用及索引文档的基本操作 Lucene系列(三)查询及高亮 一 准备 创建项目并添加Maven依赖 <dependenc ...
- Ubuntu 17.10 安装 “爱壁纸” 时,缺失了 python-support 依赖
Ubuntu 17.10 安装 "爱壁纸" 的 deb 包时,缺失了 python-support 依赖.使用 sudo apt-get -f install 也没修复.查了下官 ...
- static作用(修饰函数、局部变量、全局变量)转自http://www.cnblogs.com/stoneJin/archive/2011/09/21/2183313.html
static作用(修饰函数.局部变量.全局变量) 在C语言中,static的字面意思很容易把我们导入歧途,其实它的作用有三条. (1)先来介绍它的第一条也是最重要的一条:隐藏. 当我们同时编译多个文件 ...