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. HQL查询——关联和连接

    HQL查询--关联和连接 为了便于理解有关的使用关联和连接进行HQL查询,首先提供两个具有关联关系的持久化类:Person类和MyEvent类 Person类: import javax.persis ...

  2. (转)解决Mac OS X上PhpStorm不能输入中文

    看到Netbeans上类似问题的解决办法: /Applications/netbeans/NetBeans 6.7.1/Content/Resource/netbeans/etc/netbeans.c ...

  3. dubbo配置文件报错解决方案

    下载dubbo.xsd 文件 在eclipse->window->perferences->XML Catalog->Add ->File system->选择刚才 ...

  4. kali/centos 更新 java

    kali 转自:http://blog.sina.com.cn/s/blog_5736d8870102w15u.html 墙内的论坛上和博客上有很多这样的文章了,不过一般过程都很复杂,让人看的头晕眼花 ...

  5. 软件工程(C编码实践篇)总结

    陆伟丹 + 原创作品转载请注明出处 + <软件工程(C编码实践篇)>MOOC课程http://mooc.study.163.com/course/USTC-1000002006 对软件工程 ...

  6. pinpoint 安装部署

    .markdown-preview:not([data-use-github-style]) { padding: 2em; font-size: 1.2em; color: rgb(171, 178 ...

  7. 【网摘】CURL常用命令

    原文地址: http://www.thegeekstuff.com/2012/04/curl-examples/ 下载单个文件,默认将输出打印到标准输出中(STDOUT)中 curl http://w ...

  8. 实验一 DOS

    实验一.DOS实验 一.           实验目的 DOS(Disk Operating System)是一个使用得十分广泛的磁盘操作系统,就连眼下流行的Windows9x/ME系统都是以它为基础 ...

  9. Android导航栏菜单强制转换

    private void getOverflowMenu() { ViewConfiguration viewConfig = ViewConfiguration.get(this); try { F ...

  10. 学习PHP 逛的几个网站。

    PHP 第一社区 http://www.php1.cn/ 51cto php开发 http://developer.51cto.com/col/1441/ phphub https://phphub. ...