[TC6194]AllWoundUp

题目大意:

有\(A\)和\(B\)两个人。\(A\)在平面上游走,\(B\)会一直盯着\(A\)看,站在\(x\)轴某个位置上不动,并随着\(A\)的运动旋转身体。\(A\)的移动轨迹是一个闭合折线,包含\(n(n\le1000)\)条线段。试最大化\(B\)逆时针旋转的次数。

思路:

\(A\)的移动轨迹将\(x\)轴分成若干段。对于同一段上的点,无论\(B\)站在哪个位置效果都是一样的。枚举\(B\)所在的位置,枚举\(A\)移动路径上的每一条边,计算\(A\)令\(B\)旋转的角度即可。

源代码:

#include<cmath>
#include<vector>
#include<algorithm>
#define double long double
class AllWoundUp {
private:
static const int N=1000;
struct Point {
double x,y;
double operator * (const Point &rhs) const {
return x*rhs.y-y*rhs.x;
}
Point operator - (const Point &rhs) const {
return (Point){x-rhs.x,y-rhs.y};
}
double operator ^ (const Point &rhs) const {
return x*rhs.x+y*rhs.y;
}
};
Point p[N];
double c[N];
int n,m;
bool in(const double &x,const double &x1,const double &x2) const {
return std::min(x1,x2)<=x&&x<=std::max(x1,x2);
}
double calc(const Point &a,const Point &b) const {
return atan2(a*b,a^b);
}
int solve(const double &x0) const {
double angle=0;
const Point c=(Point){x0,0};
for(register int i=0;i<n;i++) {
const int j=(i+1)%n;
if(p[i].y==0&&p[j].y==0&&in(x0,p[i].x,p[j].x)) return 0;
angle+=calc(p[i]-c,p[j]-c);
}
return angle/M_PI/2;
}
public:
int maxWind(const std::vector<int> &v1,const std::vector<int> &v2) {
n=v1.size();
for(register int i=0;i<n;i++) p[i].x=v1[i];
for(register int i=0;i<n;i++) p[i].y=v2[i];
for(register int i=0;i<n;i++) {
const int j=(i+1)%n;
if(p[i].y*p[j].y>0||p[i].y==p[j].y) continue;
if(p[i].x!=p[j].x) {
const double k=(p[i].y-p[j].y)/(p[i].x-p[j].x);
const double b=p[i].y-k*p[i].x;
c[m++]=-b/k;
} else {
c[m++]=p[i].x;
}
}
if(m==0) return 0;
std::sort(&c[0],&c[m]);
m=std::unique(&c[0],&c[m])-c;
int ans=0;
for(register int i=1;i<m;i++) {
ans=std::max(ans,solve((c[i-1]+c[i])/2));
}
return ans;
}
};

[TC6194]AllWoundUp的更多相关文章

  1. topcoder srm 300 div1

    problem1 link 直接模拟即可. import java.util.*; import java.math.*; import static java.lang.Math.*; public ...

随机推荐

  1. 洛谷 1.5.1 Number Triangles 数字金字塔

    Description 考虑在下面被显示的数字金字塔. 写一个程序来计算从最高点开始在底部任意处结束的路径经过数字的和的最大. 每一步可以走到左下方的点也可以到达右下方的点. 7 3 8 8 1 0 ...

  2. 【洛谷 P2147】 [SDOI2008]洞穴勘测(LCT)

    题目链接 LCT裸题.. #include <cstdio> #define R register int #define I inline void #define lc c[x][0] ...

  3. jquery实现简单轮播

    先上简单的html代码 <!DOCTYPE HTML> <html> <head> <link rel="stylesheet" type ...

  4. 爬虫--selenium

    什么是selenium? 基本使用 from selenium import webdriver from selenium.webdriver.common.by import By from se ...

  5. 常用的css3新特性总结

    1:CSS3阴影 box-shadow的使用和技巧总结: 基本语法是{box-shadow:[inset] x-offset y-offset blur-radius spread-radiuscol ...

  6. c++鼠标点点,获取坐标值,放入到txt文件中

    // oj3.cpp : Defines the entry point for the console application.// #include "stdafx.h"#in ...

  7. 1.第一个hello word

    1.生产者 #!/usr/bin/env python import pika connection = pika.BlockingConnection(pika.ConnectionParamete ...

  8. POJ 1218 THE DRUNK JAILER(类开灯问题,完全平方数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2188 题目大意:n为5-100之间的一个数,代表有多少间牢房,刚开始所有房间打开,第一轮2的倍数的房间 ...

  9. xcode没有ios7的模拟器

    xcode7 目前只支持 ios8盒和iOS9的模拟器如果是Yosemite系统,下载xcode7和xcode6.4,两个版本可以共存,然后再下载iOS7默契你如果是EI Caption系统,网上说E ...

  10. open()函数文件操作

    open函数,该函数用于文件处理 操作文件时,一般需要经历如下步骤: (1)打开文件 (2)操作文件 一.打开文件     文件句柄 = open("文件路径","模式& ...