2002-2003 ACM-ICPC Northeastern European Regional Contest (NEERC 02)
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)的更多相关文章
- 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, ...
- 2002-2003 ACM-ICPC Northeastern European Regional Contest (NEERC 02) A Amusing Numbers (数学)
其实挺简单的.先直接算出之前已经排在k这个数前面的数字.比如543是三位的,那么100~543都是可以的,两位的10~54. 如果还需要往前面补的话,那么依次考虑1000~5430,5430是上界不能 ...
- 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 个时刻 ...
- 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 ...
- 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 ...
- 2015-2016 ACM-ICPC Northeastern European Regional Contest (NEERC 15)C - Cactus Jubilee
题意:给一颗仙人掌,要求移动一条边,不能放在原处,移动之后还是一颗仙人掌的方案数(仙人掌:无向图,每条边只在一个环中),等价于先删除一条边,然后加一条边 题解:对于一颗仙人掌,分成两种边,1:环边:环 ...
- 2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17) 日常训练
A - Archery Tournament 题目大意:按时间顺序出现靶子和射击一个位置,靶子的圆心为(x, y)半径为r,即圆与x轴相切,靶子不会重叠,靶子被击中后消失, 每次射击找出哪个靶子被射中 ...
- 2015-2016 ACM-ICPC Northeastern European Regional Contest (NEERC 15)
NEERC 15 题解1 题解2 官方题解
- 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 ...
随机推荐
- 通过源码编译安装VIM
开发中使用的是Ubuntu 12.04 LTS,通过sudo apt-get install vim安装的版本较低,不支持YCM,所以,用源码编译并安装最新的Vim. 卸载旧版本的Vim: sudo ...
- c++,友元类和友元函数
都是声明时友元的东西可以访问自己类的私有和保护成员 类的友元 友元是C++提供的一种破坏数据封装和数据隐藏的机制. 通过将一个模块声明为另一个模块的友元,一个模块能够引用到另一个模块中本是被隐藏的信息 ...
- HDU 4990 Reading comprehension 矩阵快速幂
题意: 给出一个序列, \(f_n=\left\{\begin{matrix} 2f_{n-1}+1, n \, mod \, 2=1\\ 2f_{n-1}, n \, mod \, 2=0 \end ...
- Python虚拟机函数机制之无参调用(一)
PyFunctionObject对象 在Python中,任何一个东西都是对象,函数也不例外.函数这种抽象机制,是通过一个Python对象——PyFunctionObject来实现的 typedef s ...
- 【Beta】Scrum meeting 2
第一天:2019/6/25 前言: 第1次会议在6月日25由PM在教10-101召开. 明确所有任务要求,根据每个人的特长和项目需求分发任务,并明确项目前进方向.时长50min. 本日任务完成情况 成 ...
- php isset()与empty()详解
bool isset(mixed var);[;mixed var[,...]] 这个函数需要一个变量名称作为参数,如果这个变量存在,则返回true,否则返回false. 也可以传递一个由逗号间隔的变 ...
- verilog写的LCD1602 显示
在读本文之前,请先阅读 LCD1602 的 datasheet(百度到处都是) ,熟悉有关的11条指令集. LCD1602的11个指令集链接 http://www.cnblogs.com/aslmer ...
- [python 函数学习篇]默认参数
python函数: 默认参数: retries= 这种形式 def ask_ok(prompt, retries=, complaint='Yes or no, please!'): while Tr ...
- 常用类--Date日期类,SimpleDateFormat日期格式类,Calendar日历类,Math数学工具类,Random随机数类
Date日期类 Date表示特定的时间,精确到毫秒; 构造方法: public Data() public Date(long date) 常用方法: public long getTime() pu ...
- iOS学习笔记43-Swift(三)类
一.Swift的类class 作为一门面向对象语言,类也是Swift的非常重要的类型,我们先来看下一个简单的类 //Swift中一个类可以不继承于任何其他基类,那么此类本身就是一个基类 class P ...