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. Angular Mobile UI API文档

    这个是angular-mobile-ui的主要模块 应用这个模块你也将同时获取到mobile-angular-ui.core和mobile-angular-ui.components的特性 他不在需要 ...

  2. 微信touchmove不生效

    最近在写一个微信里面滑动切换图片的功能,发现在chrome下都正常显示,可是在微信和qq浏览器里面就是不行. 经过一番排查,发现了问题: touchmove只触发了一次. 解决方案: 在touchst ...

  3. 微信小程序-上传下载

    wx.uploadFile(OBJECT) 上传 将本地资源上传到开发者服务器.如页面通过 wx.chooseImage(图片)/wx.chooseVideo(视频) 等接口获取到一个本地资源的临时文 ...

  4. Repeater多列分别合并单元格

    GridView.Repeater合并单元格可以参考http://www.cnblogs.com/zhmore/archive/2009/04/22/1440979.html,但是原文例子是合并一列的 ...

  5. 界面布局之表格布局TableLayout+TableRow

    一.基础知识: TableLayout置底,TableRow在TableLayout的上面,而Button.TextView等控件就在TableRow之上, 另外,TableLayout之上也可以单独 ...

  6. [转] - Configuring Android Studio: IDE & VM Options, JDK, etc

    Configuring Android Studio: IDE & VM Options, JDK, etc You should not edit any files in the IDE ...

  7. 实验一 认识DOS

    #include<stdio.h> #include<string.h> void main() {       char cmd[20][20]={"dir&quo ...

  8. MVC使用Membership配置

    MVC的权限管理,环境是MVC4.5,SQL Server2008 修改前 Web.config文件: <system.web> <authentication mode=" ...

  9. 火狐浏览器 js 1到9月份 new DATE不返回时间

    new Date('2016-1'); //错误 1到9月份必须 01 02 ...... 正确 new Date('2016-01'); var nowMonth = nowMonth>=10 ...

  10. 第一章 Java的I/O演进之路

    I/O基础入门 Java的I/O演进 第一章 Java的I/O演进之路 1.1 I/O基础入门 1.1.1 Linux网络I/O模型简介 根据UNIX网络编程对I/O模型的分类,UNIX提供了5中I/ ...