B Bricks 计算几何乱搞

题意:

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

题解:

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

代码:

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

View Code

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=0;
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(),0));G[to].push_back(edge(from,0,-cost,G[from].size()-1,1));
}char cc;
int min_cost_flow(int s,int t,int f) {int res = 0;while (f > 0) {fill(dist, dist + V, INF);dist[s] = 0;bool update = 1;while (update) {update = 0;for (int v = 0; v < V; v++) {if (dist[v] == INF)continue;for (int i = 0; i < G[v].size(); i++) {edge &e = G[v][i];if (e.cap > 0 && 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 = 1;}}}}if (dist[t] == INF)return -1;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)+1;}
};typedef build shelter;build bu[MAX_V];
shelter sh[MAX_V];int plan;
int S=0;int main() {ifstream cin("evacuate.in");ofstream cout("evacuate.out");cin.sync_with_stdio(false);cin >> n >> m;for (int i = 0; i < n; i++) {cin >> bu[i].x >> bu[i].y >> bu[i].c;S += bu[i].c;}for (int i = 0; i < m; i++)cin >> sh[i].x >> sh[i].y >> sh[i].c;for (int i = 0; i < n; i++)for (int j = 0; j < m; j++) {int k;cin >> k;plan += k * bu[i].dis(sh[j]);}for (int i = 0; i < n; i++)add_edge(n + m, i, bu[i].c, 0);for (int j = 0; j < m; j++)add_edge(j + n, n + m + 1, sh[j].c, 0);for (int i = 0; i < n; i++)for (int j = 0; j < m; j++)add_edge(i, j + n, INF, bu[i].dis(sh[j]));V = n + m + 2;int tmp = min_cost_flow(n + m, n + m + 1, S);if (tmp == plan) {cout << "OPTIMAL" << endl;return 0;}cout << "SUBOPTIMAL" << endl;for (int i = 0; i < n; i++, cout << endl)for (int j = 0; j < G[i].size(); j++)if (!G[i][j].isRev)cout << INF - G[i][j].cap << " ";return 0;
}

View Code

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[4];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[0] = 2 * M + 1;d[1] = 1;d[2] = M + 1;d[3] = M;for (int i = 0; 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[1] + y1 * d[0];int v = x2 * d[1] + y2 * d[0];int t;if (x1 == x2)t = 0;else if (y1 == y2)t = 1;else if (x2 > x1)t = 2;else t = 3;kn[i] = knife(u, v, t);}kn[K++] = knife(0, M, 1);kn[K++] = knife(N * d[0], N * d[0] + M * d[1], 1);kn[K++] = knife(0, N * d[0], 0);kn[K++] = knife(M, N * d[0] + M, 0);for (int i = 0; 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 = -1;for (int i = 0; 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] > 1) {V = max(V, u);V = max(V, p);G[p].push_back(u);G[u].push_back(p);p = u;}}}int ans = 0;V++;for (int u = 0; u < V; u++)sort(G[u].begin(), G[u].end());for (int u = 0; 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/6 << endl;return 0;
}

View Code

转载于:https://www.cnblogs.com/HarryGuo2012/p/4782582.html

2002-2003 ACM-ICPC Northeastern European Regional Contest (NEERC 02)相关推荐

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

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

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

    NEERC 15 题解1 题解2 官方题解 转载于:https://www.cnblogs.com/NEVERSTOPAC/p/5682661.html

  3. 2016-2017 ACM-ICPC Northeastern European Regional Contest (NEERC 16)

    A:模拟 注意各种情况和细节~ 1 #include<cstdio> 2 #include<string> 3 #include<cstdlib> 4 #inclu ...

  4. 2016 ACM / ICPC Asia dalian Regional Contest 题解(11 / 11)【每日亿题2021 / 2 / 17】

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A .(2017 ACM ICPC dalian H)To begin or not to be ...

  5. ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)A ASCII Area

    A: 给你一个矩阵求'/' 和 '\' 围成的图形,简单签到题,有一些细节要考虑. 题解:一行一行的跑,遇到'/'和'\' 就加0.5, 在面积里面的'.' 就加1.用一个flag来判断是否在围住的图 ...

  6. ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)G GCD Guessing Game

    G: 要你去才Paul的年龄,Paul的年龄在1~n之间,你每猜一个Paul会告诉你,你猜的这个数和他年龄的gcd,问在最坏情况下最少要猜多少次. 题解: 什么是最坏情况,我们直到如果他的年龄是1的话 ...

  7. ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)B Binary Encoding

    B: 现在有一种新的2进制表示法,要你求出0~m-1的每个数的表示. 规则如下:n 是满足 m<=2n 最小数. 而0~m-1的数只能够用n-1个位和n个位来表示. 对于n个位表示的数来说不能有 ...

  8. 2017 ACM ICPC Asia Shenyang Regional Contest 题解(10 / 13)【每日亿题2 / 16】

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A.(2017 ICPC shenyang I)Little Boxes B.(2017 ICP ...

  9. 2018-2019 ICPC Northwestern European Regional Programming Contest (NWERC 2018)

    2018-2019 ICPC Northwestern European Regional Programming Contest (NWERC 2018) 题号 题目 知识点 难度 A Access ...

最新文章

  1. b站弹幕 xml php 乱码,B站弹幕Python爬行XML响应中的代码转换问题,python,之,取,b,xml,时,转码...
  2. Javascript刷题 》 查找数组元素位置
  3. 手把手教你使用Flask轻松部署机器学习模型(附代码链接) | CSDN博文精选
  4. 函数实现十进制转二进制
  5. Windows 下 tail 查看日志命令工具分享
  6. p2148 [SDOI2009]ED
  7. NSGA-II入门C1
  8. shell中trap捕捉到信号的处理
  9. 一步步编写操作系统 20 x86虚拟bochs一般用法 上
  10. 依赖倒置原则_C#教您一步步摆脱面向过程:依赖倒置
  11. Java 面向对象面试题
  12. 关于WIN10显示“未安装任何音频输出设备” 英特尔(R)智音系统OED启动错误(代号10)解决办法
  13. IntelliJ IDEA常见问题解决办法汇总
  14. 高效科研神器——文献阅读篇
  15. 硬件电路之运算放大器3--比较器和跟随器
  16. 人脸识别相机对人脸库进行增删改查——MQTT协议
  17. Springboot定时任务、Quartz表达式
  18. 干货 | 产品助理入门攻略(一枚入行3年的PM内心独白)
  19. Ambarella SDK build 步骤解析
  20. I Want to Know

热门文章

  1. ThinkPHP的RBAC(基于角色权限控制)详解
  2. JS 网页自动加载js函数
  3. ThinkPHP实现支付宝接口功能
  4. 天津科技大学中外合作办学计算机科学怎么样,天津科技大学计算机类(中外合作办学)(计算机科学与技术(信息处理专业2016年在安徽理科高考录取最低分数线...
  5. 实战系列-Java中线程安全集合类(二)
  6. 大厂面试算法系列-如何实现链表的逆序(二)-递归法
  7. java堆缓冲区,Java NIO之Buffer(缓冲区)
  8. 深入详解Redis布隆过滤器
  9. python设计模式3-抽象工厂模式
  10. Redis:数据并发竞争顺序性