B Bricks 计算几何乱搞

题意:

给你个立方体,问你能不能放进一个管道里面。

题解:

这是一道非常迷的题,其问题在于,你可以不正着放下去,你需要斜着放。此时你需要枚举你旋转的角度,来判断是否可行。至于枚举的范围和步长,看脸乱搞。

代码:

//#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<fstream>
using namespace std; long double x[],y[]; const long double pi=acos(-); long double a,b;
long double d,e; const long double eps=1e-; int main() {
ifstream cin("bricks.in");
ofstream cout("bricks.out");
cin.sync_with_stdio(false);
cin >> x[] >> x[] >> x[] >> y[] >> y[];
sort(x, x + );
sort(y, y + );
a = x[], b = x[];
d = y[], e = y[];
if (d - a > -eps && e - b > -eps) {
cout << "YES" << endl;
return ;
}
long double dd = pi / ( * (3e6));
for (long double t = acos(e / b); t < asin(d / b) + dd; t += dd) {
if (min((e - b * cos(t)) / sin(t), (d - b * sin(t)) / cos(t)) > a - eps) {
cout << "YES" << endl;
return ;
}
}
cout << "NO" << endl;
return ;
}

E Evacuation Plan 最小费用流

题意:

题目好长好长好长。。。。。简单说就是,发生核战争了,人们要避难,给你每个建筑的坐标,给你每个避难所的坐标,每个建筑里面有若干人,从一个建筑到一个避难所的时间,是坐标的曼哈顿距离,现在要你使总时间花费最少。

题解:

就最小费用的模板题。最后在残余网络上寻找解即可。

代码:

//#include <iostream>
#include<vector>
#include<fstream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<string>
#include<cmath>
#define MAX_V 222
#define INF 1008611
using namespace std;
struct edge {
public:
int to, cap, cost, rev;
bool isRev; edge(int t, int c, int co, int re,bool ir) : to(t), cap(c), cost(co), rev(re),isRev(ir) { } edge() { }
};
int V=;
vector<edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V]; void add_edge(int from,int to,int cap,int cost) {
G[from].push_back(edge(to,cap,cost,G[to].size(),));
G[to].push_back(edge(from,,-cost,G[from].size()-,));
} char cc;
int min_cost_flow(int s,int t,int f) {
int res = ;
while (f > ) {
fill(dist, dist + V, INF);
dist[s] = ;
bool update = ;
while (update) {
update = ;
for (int v = ; v < V; v++) {
if (dist[v] == INF)continue;
for (int i = ; i < G[v].size(); i++) {
edge &e = G[v][i];
if (e.cap > && dist[e.to] > dist[v] + e.cost) {
//cout<<"*"<<endl;
dist[e.to] = dist[v] + e.cost;
prevv[e.to] = v;
preve[e.to] = i;
update = ;
}
}
}
}
if (dist[t] == INF)
return -; int d = f;
for (int v = t; v != s; v = prevv[v])
d = min(d, G[prevv[v]][preve[v]].cap);
f -= d;
res += d * dist[t];
for (int v = t; v != s; v = prevv[v]) {
edge &e = G[prevv[v]][preve[v]];
e.cap -= d;
G[v][e.rev].cap += d;
}
}
return res;
} int n,m; struct build {
public:
int x, y,c; build(int xx, int yy,int cc) : x(xx), y(yy), c(cc){ } build() { } int dis(build a){
return abs(a.x-x)+abs(a.y-y)+;
}
}; typedef build shelter; build bu[MAX_V];
shelter sh[MAX_V]; int plan;
int S=; int main() {
ifstream cin("evacuate.in");
ofstream cout("evacuate.out");
cin.sync_with_stdio(false);
cin >> n >> m;
for (int i = ; i < n; i++) {
cin >> bu[i].x >> bu[i].y >> bu[i].c;
S += bu[i].c;
}
for (int i = ; i < m; i++)
cin >> sh[i].x >> sh[i].y >> sh[i].c;
for (int i = ; i < n; i++)
for (int j = ; j < m; j++) {
int k;
cin >> k;
plan += k * bu[i].dis(sh[j]);
}
for (int i = ; i < n; i++)
add_edge(n + m, i, bu[i].c, );
for (int j = ; j < m; j++)
add_edge(j + n, n + m + , sh[j].c, );
for (int i = ; i < n; i++)
for (int j = ; j < m; j++)
add_edge(i, j + n, INF, bu[i].dis(sh[j]));
V = n + m + ;
int tmp = min_cost_flow(n + m, n + m + , S);
if (tmp == plan) {
cout << "OPTIMAL" << endl;
return ;
}
cout << "SUBOPTIMAL" << endl;
for (int i = ; i < n; i++, cout << endl)
for (int j = ; j < G[i].size(); j++)
if (!G[i][j].isRev)
cout << INF - G[i][j].cap << " "; return ;
}

I Inlay Cutters 模拟+图论

题意:

给你一个棋盘,现在切若干刀,问你最后有几个三角形。

题解:

由于三个点在平面上只能构成三角形,那么此题可以转化为图论问题来解决,将相邻的直线交点连边,然后在图上求有多少个三元环即可。

代码:

//#include<iostream>
#include<fstream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#define MAX_N 10004
using namespace std; int N,M,K; int d[]; struct knife {
public:
int from, to, dir; knife(int f, int t, int d) : from(f), to(t), dir(d) { } knife() { }
}; knife kn[MAX_N]; int cnt[MAX_N]; vector<int> G[MAX_N]; int main() {
ifstream cin("inlay.in");
ofstream cout("inlay.out");
cin.sync_with_stdio(false);
cin >> M >> N >> K;
d[] = * M + ;
d[] = ;
d[] = M + ;
d[] = M;
for (int i = ; i < K; i++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (y1 > y2 || (y1 == y2 && x1 > x2)) {
swap(x1, x2);
swap(y1, y2);
}
int u = x1 * d[] + y1 * d[];
int v = x2 * d[] + y2 * d[];
int t;
if (x1 == x2)t = ;
else if (y1 == y2)t = ;
else if (x2 > x1)t = ;
else t = ;
kn[i] = knife(u, v, t);
}
kn[K++] = knife(, M, );
kn[K++] = knife(N * d[], N * d[] + M * d[], );
kn[K++] = knife(, N * d[], );
kn[K++] = knife(M, N * d[] + M, );
for (int i = ; i < K; i++) {
int u = kn[i].from, v = kn[i].to, t = kn[i].dir;
while (u != v) {
cnt[u]++;
u += d[t];
}
cnt[v]++;
}
int V = -;
for (int i = ; i < K; i++) {
int u = kn[i].from, v = kn[i].to, t = kn[i].dir;
int p = u;
while (u != v) {
u += d[t];
if (cnt[u] > ) {
V = max(V, u);
V = max(V, p);
G[p].push_back(u);
G[u].push_back(p);
p = u;
}
}
}
int ans = ;
V++;
for (int u = ; u < V; u++)
sort(G[u].begin(), G[u].end());
for (int u = ; u < V; u++)
for (auto v:G[u])
for (auto c:G[v]) {
if (c == u)continue;
int t = lower_bound(G[c].begin(), G[c].end(), u) - G[c].begin();
if (G[c][t] == u)ans++;
//cout<<c<<" "<<u<<" "<<v<<endl;
}
cout << ans/ << endl;
return ;
}

2002-2003 ACM-ICPC Northeastern European Regional Contest (NEERC 02)的更多相关文章

  1. 2002-2003 ACM-ICPC Northeastern European Regional Contest (NEERC 02) H Heroes Of Might And Magic (隐含dp)

    问题是求一个方案,实际隐含一个dp.法力是递减的,所以状态是DAG,对于一个确定的状态,我们贪心地希望英雄的血量尽量大. 分析:定义状态dp[i][p][h]表示是已经用了i的法力值,怪兽的位置在p, ...

  2. 2002-2003 ACM-ICPC Northeastern European Regional Contest (NEERC 02) A Amusing Numbers (数学)

    其实挺简单的.先直接算出之前已经排在k这个数前面的数字.比如543是三位的,那么100~543都是可以的,两位的10~54. 如果还需要往前面补的话,那么依次考虑1000~5430,5430是上界不能 ...

  3. 2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17)

    2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17) A 题意:有 n 个时刻 ...

  4. Editing 2011-2012 ACM-ICPC Northeastern European Regional Contest (NEERC 11)

    NEERC 11 *wiki链接[[https://acm.ecnu.edu.cn/wiki/index.php?title=2011-2012_ACM-ICPC_Northeastern_Europ ...

  5. 2012-2013 ACM-ICPC Northeastern European Regional Contest (NEERC 12)

    Problems     # Name     A Addictive Bubbles1 addictive.in / addictive.out 2 s, 256 MB    x438 B Blin ...

  6. 2015-2016 ACM-ICPC Northeastern European Regional Contest (NEERC 15)C - Cactus Jubilee

    题意:给一颗仙人掌,要求移动一条边,不能放在原处,移动之后还是一颗仙人掌的方案数(仙人掌:无向图,每条边只在一个环中),等价于先删除一条边,然后加一条边 题解:对于一颗仙人掌,分成两种边,1:环边:环 ...

  7. 2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17) 日常训练

    A - Archery Tournament 题目大意:按时间顺序出现靶子和射击一个位置,靶子的圆心为(x, y)半径为r,即圆与x轴相切,靶子不会重叠,靶子被击中后消失, 每次射击找出哪个靶子被射中 ...

  8. 2015-2016 ACM-ICPC Northeastern European Regional Contest (NEERC 15)

    NEERC 15 题解1 题解2 官方题解

  9. ACM ICPC 2010–2011, Northeastern European Regional Contest St Petersburg – Barnaul – Tashkent – Tbilisi, November 24, 2010

    ACM ICPC 2010–2011, Northeastern European Regional Contest St Petersburg – Barnaul – Tashkent – Tbil ...

随机推荐

  1. 多线程辅助类之CountDownLatch(三)

    CountDownLatch信号灯是一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待.它可以实现多线程的同步互斥功能,和wait和notify方法实现功能类似,具体 ...

  2. Anaconda安装和环境的搭建

    Anaconda安装 在官网上下载最新的Anaconda https://www.anaconda.com/distribution/ 我使用的是2018.12,Python 3.7这个版本的. 安装 ...

  3. LOJ 101 最大流(ISAP 模板)

    开long long的最大流 #include<bits/stdc++.h> using namespace std; ;//点数的最大值 ;//边数的最大值 ; struct Edge ...

  4. Power Calculus UVA - 1374 迭代加深搜索

    迭代加深搜索经典题目,好久不做迭代加深搜索题目,拿来复习了,我们直接对当前深度进行搜索,注意剪枝,还有数组要适当开大,因为2^maxd可能很大 题目:题目链接 AC代码: #include <i ...

  5. 动态规划:Codeforces Round #427 (Div. 2) C Star sky

    C. Star sky time limit per test2 seconds memory limit per test256 megabytes inputstandard input outp ...

  6. Windows下新建多级文件夹

    使用system函数调用系统命令"md" 注意:字符串变量的话赋值时要使用双斜杠"\\": system("md C:\\newfolder\\&qu ...

  7. python 模块相互import

    模块A中import B,而在模块B中import A.这时会怎么样呢?这个在Python列表中由RobertChen给出了详细解释,抄录如下: [A.py] from B import D clas ...

  8. mysql PacketTooBigException 的处理方式

    SHOW VARIABLES LIKE '%max_allowed_packet%'; set global max_allowed_packet = 2*1024*1024*1000

  9. JS实现——Base64编码解码,带16进制显示

    在网上找了个JS实现的Base64编码转换,所以就想自己研究下,界面如下: 将代码以BASE64方式加密.解密 请输入要进行编码或解码的字符: 编码结果以ASCII码16进制显示 解码结果以ASCII ...

  10. Python 协程、IO模型

    1.协程(单线程实现并发)2.I/0模型 2.1阻塞I/O 2.2非阻塞I/O 知识点一:协程 协程的目的:是想要在单线程下实现并发(并发看起来是同时运行的) 并发=多个任务间切换+保存状态(正常情况 ...