HDU 4666 Hyperspace

曼哈顿距离:|x1-x2|+|y1-y2|。

最远曼哈顿距离,枚举x1与x2的关系以及y1与y2的关系,取最大值就是答案。

 #include<cstdio>
#include<set>
#define oo 0x7FFFFFFF
#define MAXM 35
#define MAXN 100010
using namespace std;
multiset<int> myset[MAXM];
struct Ask {
int cmd;
int arr[MAXM];
} q[MAXN];
int main() {
int n, m;
int i, j, k;
int tmp;
int res;
int ans;
multiset<int>::iterator it1, it2;
while (~scanf("%d%d", &n, &m)) {
for (i = ; i < MAXM; i++) {
myset[i].clear();
}
for (i = ; i <= n; i++) {
scanf("%d", &q[i].cmd);
if (q[i].cmd == ) {
for (j = ; j < m; j++) {
scanf("%d", &q[i].arr[j]);
}
} else {
scanf("%d", &tmp);
q[i].cmd = q[tmp].cmd ^ ;
for (j = ; j < m; j++) {
q[i].arr[j] = q[tmp].arr[j];
}
}
}
for (i = ; i <= n; i++) {
if (q[i].cmd == ) {
for (j = ; j < ( << m); j++) {
tmp = j;
res = ;
for (k = ; k < m; tmp >>= , k++) {
if (tmp & ) {
res -= q[i].arr[k];
} else {
res += q[i].arr[k];
}
}
myset[j].insert(res);
}
} else {
for (j = ; j < ( << m); j++) {
tmp = j;
res = ;
for (k = ; k < m; tmp >>= , k++) {
if (tmp & ) {
res -= q[i].arr[k];
} else {
res += q[i].arr[k];
}
}
myset[j].erase(myset[j].find(res));
}
}
ans = -oo;
for (j = ; j < ( << m); j++) {
if (myset[j].size() > ) {
break;
}
}
if (j >= ( << m)) {
ans = ;
} else {
for (j = ; j < ( << m); j++) {
if (myset[j].size() > ) {
it1 = myset[j].end();
it1--;
it2 = myset[j].begin();
ans = max(ans, (*it1 - *it2));
}
}
}
printf("%d\n", ans);
}
}
return ;
}

HDU 4667 Building Fence

三角形上的点当作普通点。

点与圆的切点可能是凸包上的点。

两圆公切线与圆的交点也可能是凸包上的点。

凸包上两个点属于同一个圆,则长度等于弧长。否则长度就是线段距离。

 #include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
#define MAXN 500010
#define EPS 1e-8
const double PI = acos(-1.0);
using namespace std;
struct Point {
double x, y;
int idx;
Point(double _x = , double _y = , int _idx = ) {
x = _x;
y = _y;
idx = _idx;
}
};
struct Circle {
Point o;
double r;
};
vector<Point> p;
Point st[MAXN];
int top;
Circle c[MAXN];
inline int dbcmp(double x, double y) {
if (fabs(x - y) < EPS) {
return ;
} else {
return x > y ? : -;
}
}
bool cmp(Point p1, Point p2) {
if (dbcmp(p1.y, p2.y)) {
return p1.y < p2.y;
} else {
return p1.x < p2.x;
}
}
Point operator+(Point p1, Point p2) {
return Point(p1.x + p2.x, p1.y + p2.y);
}
Point operator-(Point p1, Point p2) {
return Point(p1.x - p2.x, p1.y - p2.y);
}
Point operator*(Point p1, double k) {
return Point(p1.x * k, p1.y * k);
}
Point Rotate(Point p, double angle) {
Point res;
res.x = p.x * cos(angle) - p.y * sin(angle);
res.y = p.x * sin(angle) + p.y * cos(angle);
return res;
}
void TangentPoint_PC(Point poi, Point o, double r, Point &result1,
Point &result2) {
double line = sqrt(
(poi.x - o.x) * (poi.x - o.x) + (poi.y - o.y) * (poi.y - o.y));
double angle = acos(r / line);
Point unitvector, lin;
lin.x = poi.x - o.x;
lin.y = poi.y - o.y;
unitvector.x = lin.x / sqrt(lin.x * lin.x + lin.y * lin.y) * r;
unitvector.y = lin.y / sqrt(lin.x * lin.x + lin.y * lin.y) * r;
result1 = Rotate(unitvector, -angle);
result2 = Rotate(unitvector, angle);
result1.x += o.x;
result1.y += o.y;
result2.x += o.x;
result2.y += o.y;
return;
}
inline double dist(Point p1, Point p2) {
return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
void TangentPoint_CC(Circle c1, Circle c2) {
if (dbcmp(c1.r, c2.r) > ) {
swap(c1, c2);
}
double c2c = dist(c1.o, c2.o);
double height = c2.r - c1.r;
double alpha = asin(height / c2c) + PI / ;
Point v1, v2, tmp;
v1 = c2.o - c1.o;
double len = dist(v1, Point(, ));
v1.x /= len;
v1.y /= len; v2 = Rotate(v1, alpha);
tmp = v2 * c1.r + c1.o;
tmp.idx = c1.o.idx;
p.push_back(tmp);
tmp = v2 * c2.r + c2.o;
tmp.idx = c2.o.idx;
p.push_back(tmp); v2 = Rotate(v1, -alpha);
tmp = v2 * c1.r + c1.o;
tmp.idx = c1.o.idx;
p.push_back(tmp);
tmp = v2 * c2.r + c2.o;
tmp.idx = c2.o.idx;
p.push_back(tmp);
}
inline double xmult(Point p0, Point p1, Point p2) {
return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
}
double dot(Point a, Point b) {
return a.x * b.x + a.y * b.y;
}
double cross(Point a, Point b) {
return a.x * b.y - a.y * b.x;
}
double len(Point a) {
return sqrt(a.x * a.x + a.y * a.y);
}
double angle(Point a, Point b) {
double ret = acos(dot(a, b) / (len(a) * len(b)));
if (cross(a, b) > ) {
return ret;
} else {
return * PI - ret;
}
}
int main() {
int n, m;
int i, j;
double x, y;
int tmp;
Point p1, p2;
double ans;
while (~scanf("%d%d", &n, &m)) {
p.clear();
for (i = ; i < n; i++) {
scanf("%lf%lf%lf", &x, &y, &c[i].r);
c[i].o = Point(x, y, i);
}
for (i = ; i < m; i++) {
for (j = ; j < ; j++) {
scanf("%lf%lf", &x, &y);
p.push_back(Point(x, y, -));
}
}
for (i = ; i < n; i++) {
for (j = ; j < * m; j++) {
TangentPoint_PC(p[j], c[i].o, c[i].r, p1, p2);
p1.idx = p2.idx = c[i].o.idx;
p.push_back(p1);
p.push_back(p2);
}
}
for (i = ; i < n; i++) {
for (j = i + ; j < n; j++) {
TangentPoint_CC(c[i], c[j]);
}
}
sort(p.begin(), p.end(), cmp);
top = -;
for (i = ; i < (int) p.size(); i++) {
while (top > && dbcmp(xmult(st[top - ], st[top], p[i]), ) <= ) {
top--;
}
st[++top] = p[i];
}
tmp = top;
for (i = p.size() - ; i >= ; i--) {
while (top > tmp && dbcmp(xmult(st[top - ], st[top], p[i]), ) <= ) {
top--;
}
st[++top] = p[i];
}
if (n == && m == ) {
ans = * PI * c[].r;
} else {
ans = ;
for (i = ; i < top; i++) {
if (st[i].idx < || st[i + ].idx <
|| st[i].idx != st[i + ].idx) {
ans += dist(st[i], st[i + ]);
} else {
ans += c[st[i].idx].r
* angle(st[i] - c[st[i].idx].o,
st[i + ] - c[st[i].idx].o);
}
}
}
printf("%.5lf\n", ans);
}
return ;
}

【 2013 Multi-University Training Contest 7 】的更多相关文章

  1. 【 2013 Multi-University Training Contest 8 】

    HDU 4678 Mine 对于每个空白区域,求SG值. 最后异或起来等于0,先手必败. #pragma comment(linker,"/STACK:102400000,102400000 ...

  2. 【 2013 Multi-University Training Contest 6 】

    HDU 4655 Cut Pieces 假设n个数构成的总数都分成了n段,总数是n*a1*a2*...*an.但是答案显然不会那么多. 对于相邻的两个ai,ai+1,如果选择相同的颜色,那么就减少了a ...

  3. 【 2013 Multi-University Training Contest 5 】

    HDU 4647 Another Graph Game 如果没有边的作用,显然轮流拿当前的最大值即可. 加上边的作用,将边权平均分给两个点,如果一个人选走一条边的两个点,就获得了边的权值:如果分别被两 ...

  4. 【 2013 Multi-University Training Contest 4 】

    HDU 4632 Palindrome subsequence dp[x][y]表示区间[x,y]构成回文串的方案数. 若str[x]==str[y],dp[x][y]=dp[x+1][y]+dp[x ...

  5. 【 2013 Multi-University Training Contest 3 】

    HDU 4622 Reincarnation 枚举字符串的起点,构造后缀自动机,每次插入一个字符,就能统计得到当前不同字串的个数,预处理出所有的询问. #include<cstdio> # ...

  6. 【 2013 Multi-University Training Contest 2 】

    HDU 4611 Balls Rearrangement 令lcm=LCM(a,b),gcd=GCD(a,b).cal(n,a,b)表示sum(abs(i%a-i%b)),0<=i<n. ...

  7. 【 2013 Multi-University Training Contest 1 】

    HDU 4602 Partition f[i]表示和为i的方案数.已知f[i]=2i-1. dp[i]表示和为i,k有多少个.那么dp[i]=dp[1]+dp[2]+...+dp[i-1]+f[i-k ...

  8. 【HDU 2014 Multi-University Training Contest 1 1002】/【HDU 4862】Jump

    多校训练就这么华丽丽的到了 ,于是乎各种华丽丽的被虐也開始了. 这是多校的1002; 最小费用最大流. 题目大意: 有n*m个方格,每一个方格都一个的十进制一位的数.你能够操作K次. 对于每一次操作, ...

  9. 【2018 Multi-University Training Contest 5】

    01: 02:https://www.cnblogs.com/myx12345/p/9436953.html 03: 04: 05:https://www.cnblogs.com/myx12345/p ...

随机推荐

  1. all ,any,abs的使用

    #!/usr/bin/env python #all循环参数,如果每个元素都为真,那么all的返回值为真 r = all([True,'sad','asd']) print(r) #any 只有一个真 ...

  2. [Amazon] Amazon IAP for Unity

    1> 下载amazon IAP3.0 for unity plugin 2> 根据 https://developer.amazon.com/public/apis/earn/in-app ...

  3. TOEFL备考计划

    一.总则: 1.坚持每一天,充分利用一切可以利用的时间学英语.没有持之以恒的学习和大量的时将做保障,一切都是空谈. 2.每天听写一篇文章,以此文章为中心,展开一天的学习. OG, TOP 3.听说读写 ...

  4. 利用FlashPaper在web页面中显示PDF文件(兼容各浏览器)

    应项目需求要把PDF内嵌到网页中显示,其中有了很多办法,比如用<embed/>元素放入PDF文件,但是效果不理想,浏览器兼容不理想,在ie9/8(其他版本没有测试)显示会提示下载pdf文件 ...

  5. Redis教程(二):String数据类型

    一.概述: 字符串类型是Redis中最为基础的数据存储类型,它在Redis中是二进制安全的,这便意味着该类型可以接受任何格式的数据,如JPEG图像数据或Json对象描述信息等.在Redis中字符串类型 ...

  6. 样本、文库、重复、lane、run - 二代测序原理及名词解释

    参考: 独占鳌头的Illumina仪器(二代测序篇) HiSeq2000测序原理.流程与仪器 NGS文库制备的方法比较[心得点评] 各种测序文库构建方式 样本:就是待测的DNA.RNA或蛋白序列,样本 ...

  7. Linux基础知识

    1.url中不写端口号,默认就是80端口:本机是127.0.0.1或者localhost 2.用户管理 查看当前用户: id:可以查看当前用户:whoami:查看当前的用户:who:可以查看当前已经登 ...

  8. struts 头像上传

    java代码: 1 package cn.itcast.nsfw.user.action; import java.io.File; import java.io.IOException; impor ...

  9. 我的Time

    C++改本地时间 #include<iostream> #include<windows.h> using namespace std; void main() { //tim ...

  10. HTML5 <input>添加多张图片,可点击弹窗放大。限定4张,可删除。

    点击弹窗放大,需要加入插件. <link rel="stylesheet" href="css/photoswipe.css"> <link ...