[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. An impassioned circulation of affection(尺取+预处理)

    题目链接:http://codeforces.com/contest/814/problem/C 题目: 题意:给你一个长度为n的字符串,m次查询,每次查询:最多进行k步修改,求字符c(要输入的字符) ...

  2. python初步学习-python函数(一)

    python 函数 函数是组织好的,可重复使用的,用来实现单一或者相关联功能的代码段. 函数能提高应用的模块性和代码的重复利用率. 函数定义 python中函数定义有一些简单的规则: 函数代码块以de ...

  3. 关于angularJS的一些用法

    AngularJS 事件指令: ng-click/dblclick ng-mousedown/up ng-mouseenter/leave ng-mousemove/over/out ng-keydo ...

  4. Python作业工资管理系统(第三周)

    作业内容: 实现效果: 从info.txt文件中读取员工及其工资信息,最后将修改或增加的员工工资信息也写入原info.txt文件. 效果演示: 1. 查询员工工资 2. 修改员工工资 3. 增加新员工 ...

  5. IE9 下 ellipsis bug fix

    fiddle: http://jsfiddle.net/tagliala/TtbuG/10/ original: https://github.com/FortAwesome/Font-Awesome ...

  6. password passphrase passcode 的区别

    In general, passphrases are long passwords and passcodes are numeric-only passwords.

  7. flask插件系列之flask_celery异步任务神器

    现在继续学习在集成的框架中如何使用celery. 在Flask中使用celery 在Flask中集成celery需要做到两点: 创建celery的实例对象的名字必须是flask应用程序app的名字,否 ...

  8. centos如何设置定时任务

    1.crontab -e 打开任务列表,输入i开始编写面之后按esc退出编写默写,:wq保存退出即可. 2.关于时间格式的定义,,请使用下面的网站 https://crontab.guru/#00_0 ...

  9. 016 sleep,wait,yield,join区别

    1.线程通常有五种状态,创建,就绪,运行.阻塞和死亡状态.2.阻塞的情况又分为三种:(1).等待阻塞:运行的线程执行wait()方法,该线程会释放占用的所有资源,JVM会把该线程放入“等待池”中.进入 ...

  10. Deep Learning基础--机器翻译BLEU与Perplexity详解

    前言 近年来,在自然语言研究领域中,评测问题越来越受到广泛的重视,可以说,评测是整个自然语言领域最核心和关键的部分.而机器翻译评价对于机器翻译的研究和发展具有重要意义:机器翻译系统的开发者可以通过评测 ...