博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2017-2018 ACM-ICPC, Asia Tsukuba Regional Contest
阅读量:6613 次
发布时间:2019-06-24

本文共 10309 字,大约阅读时间需要 34 分钟。

思路:暴力枚举黑巧克力的个数和厚黑巧克力的个数

代码:

#pragma GCC optimize(2)#pragma GCC optimize(3)#pragma GCC optimize(4)#include
using namespace std;#define fi first#define se second#define pi acos(-1.0)#define LL long long//#define mp make_pair#define pb push_back#define ls rt<<1, l, m#define rs rt<<1|1, m+1, r#define ULL unsigned LL#define pll pair
#define pli pair
#define pii pair
#define piii pair
#define mem(a, b) memset(a, b, sizeof(a))#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);//headLL C(int n, int m) { LL res = 1; if(n-m < m) m = n-m; for (int i = 1; i <= m; i++) { res *= (n-i+1); res /= i; } return res;}int main() { int l, k; LL res = 1; scanf("%d %d", &l, &k); LL ans = 0; for (int i = 1; i <= 51; i++) { for (int j = 0; j <= i; j++) { if(j*k + (i-j) + i-1 <= l) { ans += C(i, j); } } } printf("%lld\n", ans); return 0;}
View Code

 

思路:预处理+暴力

代码:

#pragma GCC optimize(2)#pragma GCC optimize(3)#pragma GCC optimize(4)#include
using namespace std;#define fi first#define se second#define pi acos(-1.0)#define LL long long//#define mp make_pair#define pb push_back#define ls rt<<1, l, m#define rs rt<<1|1, m+1, r#define ULL unsigned LL#define pll pair
#define pli pair
#define pii pair
#define piii pair
#define mem(a, b) memset(a, b, sizeof(a))#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);//headint a[10], b[10];pii p[20];pii delta[20];int tmp[20][20];piii T[500];int t[500];int vv[500];int main() { int m; scanf("%d", &m); for (int i = 1; i <= m; i++) scanf("%d %d", &p[i].fi, &p[i].se); int cnt = 0; for (int i = 1; i <= m; i++) { for (int j = 1; j <= m; j++) { if(i == j) continue; int x = p[i].fi - p[j].fi; int y = p[i].se - p[j].se; int d = __gcd(x, y); x /= d; y /= d; if(x > 0 && y < 0) x = -x, y = -y; T[++cnt].fi.fi = x; T[cnt].fi.se = y; T[cnt].se = cnt; tmp[i][j] = cnt; } } sort(T+1, T+1+cnt); int now = 1; t[T[1].se] = now; for (int i = 2; i <= cnt; i++) { if(T[i].fi.fi == T[i-1].fi.fi && T[i].fi.se == T[i-1].fi.se) { t[T[i].se] = now; } else { t[T[i].se] = ++now; } } for (int i = 1; i <= m; i++) { for (int j = 1; j <= m; j++) { tmp[i][j] = t[tmp[i][j]]; } } int up = (1<
View Code

 

思路:模拟

代码:

#include
using namespace std;typedef long long ll;const int maxn=1e5+5;ll a[maxn];ll mol,den;int main(){ ll n,t; scanf("%lld%lld",&n,&t); for(int i=0;i
=0 ? t-pre1-a[i]:-den; pre1+=a[i]; printf("%lld\n",mol/den+2); }}
View Code

 

思路:先分别求出每个点到1和2的最短路d1[i], d2[i],

对于一条边u->v, 如果d1[v] + d2[u] + w < 1到2最短路径, 那么肯定是HAPPY

否则看这条边是不是1到2的所有最短路径所构成的无向图中的桥, 如果是桥, 删去后最短路肯定变大, 是SAD, 否则最短路径肯定不变, 是SOSO

代码:

#pragma GCC optimize(2)#pragma GCC optimize(3)#pragma GCC optimize(4)#include
using namespace std;#define fi first#define se second#define pi acos(-1.0)#define LL long long//#define mp make_pair#define pb push_back#define ls rt<<1, l, m#define rs rt<<1|1, m+1, r#define ULL unsigned LL#define pll pair
#define pli pair
#define pii pair
#define piii pair
#define mem(a, b) memset(a, b, sizeof(a))#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);//headconst int N = 1e5 + 5;const LL INF = 0x3f3f3f3f3f3f3f3f;vector
g[N], rg[N], tg[N];int ans[N], u[N], v[N], w[N], low[N], dfn[N], tot = 0;pii fa[N];LL d1[N], d2[N];priority_queue
, greater
> q;void Dij1(int s) { mem(d1, INF); d1[s] = 0; q.push({ 0, s}); while(!q.empty()) { pli p = q.top(); q.pop(); int u = p.se; if(p.fi > d1[u]) continue; for (pii to : g[u]) { int v = to.fi; int w = to.se; if(d1[u] + w < d1[v]) { d1[v] = d1[u] + w; q.push({d1[v], v}); } } }}void Dij2(int s) { mem(d2, INF); d2[s] = 0; q.push({ 0, s}); while(!q.empty()) { pli p = q.top(); q.pop(); int u = p.se; if(p.fi > d2[u]) continue; for (pii to : rg[u]) { int v = to.fi; int w = to.se; if(d2[u] + w < d2[v]) { d2[v] = d2[u] + w; q.push({d2[v], v}); } } }}void tarjan(int u, pii o) { low[u] = dfn[u] = ++tot; fa[u] = o; for (pii p: tg[u]) { int v = p.fi; if(!dfn[v]) { tarjan(v, {u, p.se}); low[u] = min(low[u], low[v]); } else if(v != o.fi) low[u] = min(low[u], dfn[v]); }}int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= m; i++) { scanf("%d %d %d", &u[i], &v[i], &w[i]); g[u[i]].pb({v[i], w[i]}); rg[v[i]].pb({u[i], w[i]}); } Dij1(1); Dij2(2); for (int i = 1; i <= m; i++) { if(d1[v[i]] + w[i] + d2[u[i]] < d1[2]) ans[i] = 1; else if(d1[u[i]] + w[i] + d2[v[i]] == d1[2]) { tg[u[i]].pb({v[i], i}); tg[v[i]].pb({u[i], i}); } } tarjan(1, { 1, 1}); for (int v = 2; v <= n; v++) { int u = fa[v].fi; int id = fa[v].se; if(low[v] > dfn[u]) ans[id] = 2; } for (int i = 1; i <= m; i++) { if(ans[i] == 1) puts("HAPPY"); else if(ans[i] == 2) puts("SAD"); else puts("SOSO"); } return 0;}
View Code

 

思路:将立体问题转换成平面问题

代码:

#pragma GCC optimize(2)#pragma GCC optimize(3)#pragma GCC optimize(4)#include
using namespace std;#define fi first#define se second#define pi acos(-1.0)#define LL long long//#define mp make_pair#define pb push_back#define ls rt<<1, l, m#define rs rt<<1|1, m+1, r#define ULL unsigned LL#define pll pair
#define pli pair
#define pii pair
#define piii pair
#define mem(a, b) memset(a, b, sizeof(a))#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);//headchar s[5];int w, l;double f1(double x, double c) { return sqrt(3)*x + c;}double f2(double x, double c) { return -sqrt(3)*x + c;}int solve() { scanf("%s", s); scanf("%d %d", &w, &l); if(s[0] == 'B') w += 60; else if(s[0] == 'C') w += 120; double y = l * sin(w*pi/180.0); double x = - l * cos(w*pi/180.0); while(y > 2*sqrt(3)) y -= 2*sqrt(3); while(x > 2) x -= 2; while(x < 0) x += 2; if(0 <= x && x < 1) { if(0 <= y && y <= sqrt(3)) { if(y > f1(x, 0) && y > f2(x, sqrt(3))) return 4; else if(y < f1(x, 0) && y < f2(x, sqrt(3))) return 4; else if(y > f1(x, 0) && y < f2(x, sqrt(3))) { if(y > sqrt(3)/2.0) return 2; else return 1; } else { if(y > sqrt(3)/2.0) return 1; else return 2; } } else { if(y > f1(x, sqrt(3)) && y > f2(x, 2*sqrt(3))) return 3; else if(y < f1(x, sqrt(3)) && y < f2(x, 2*sqrt(3))) return 3; else if(y > f1(x, sqrt(3)) && y < f2(x, 2*sqrt(3))) { if(y > sqrt(3)*3.0/2.0) return 1; else return 2; } else { if(y > sqrt(3)*3.0/2.0) return 2; else return 1; } } } else { if(0 <= y && y <= sqrt(3)) { if(y > f1(x, -sqrt(3)) && y > f2(x, 2*sqrt(3))) return 3; else if(y < f1(x, -sqrt(3)) && y < f2(x, 2*sqrt(3))) return 3; else if(y > f1(x, -sqrt(3)) && y < f2(x, 2*sqrt(3))) { if(y > sqrt(3)/2.0) return 1; else return 2; } else { if(y > sqrt(3)/2.0) return 2; else return 1; } } else { if(y > f1(x, 0) && y > f2(x, 3*sqrt(3))) return 4; else if(y < f1(x, 0) && y < f2(x, 3*sqrt(3))) return 4; else if(y > f1(x, 0) && y < f2(x, 3*sqrt(3))) { if(y > sqrt(3)*3.0/2.0) return 2; else return 1; } else { if(y > sqrt(3)*3.0/2.0) return 1; else return 2; } } }}int main() { if(solve() == solve()) puts("YES"); else puts("NO"); return 0;}
View Code

 

思路:

第一种就是求对于每个区间,有多少个区间与他相交, 取最大值, 这个用容斥做

第二种贪心求,每次从优先队列里取出右端点最靠前的,与当前区间左端点比较

#pragma GCC optimize(2)#pragma GCC optimize(3)#pragma GCC optimize(4)#include
using namespace std;#define fi first#define se second#define pi acos(-1.0)#define LL long long//#define mp make_pair#define pb push_back#define ls rt<<1, l, m#define rs rt<<1|1, m+1, r#define ULL unsigned LL#define pll pair
#define pli pair
#define pii pair
#define piii pair
#define mem(a, b) memset(a, b, sizeof(a))#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);//headconst int N = 2e5 + 10, M = 1e5 + 10;pii a[N];int n, bit[M], btt[M];priority_queue
, greater
> q;void add(int x, int ty) { if(ty == 1) { while(x < M) bit[x]++, x += x&-x; } else { while(x < M) btt[x]++, x += x&-x; }}int sum(int x, int ty) { int ans = 0; if(ty == 1) { while(x) ans += bit[x], x -= x&-x; } else { while(x) ans += btt[x], x -= x&-x; } return ans;}int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d %d", &a[i].fi, &a[i].se); } sort(a+1, a+1+n); for (int i = 1; i <= n; i++) { if(q.empty()) q.push(a[i].se); else { int p = q.top(); if(a[i].fi >= p) { q.pop(); q.push(a[i].se); } else q.push(a[i].se); } } int ans2 = q.size(), ans1 = 0; for (int i = 1; i <= n; i++) { add(a[i].se, 1); add(a[i].fi, 2); } for (int i = 1; i <= n; i++) { int t = n-1 - sum(a[i].fi, 1); t -= (n - sum(a[i].se-1, 2)); ans1 = max(ans1, t);// cout << a[i].fi << " " << a[i].se << " " << t << endl; } printf("%d %d\n", ans1+1, ans2); return 0;}
View Code

 

转载于:https://www.cnblogs.com/widsom/p/10008098.html

你可能感兴趣的文章
LDAP密码认证例子
查看>>
2019程序媛面试之美少女战士
查看>>
Maven经验分享(一)安装部署
查看>>
AJPFX简述abstract class和interface的区别
查看>>
黑马程序员——内部类
查看>>
校园的早晨
查看>>
[学习]拆分成二维数组
查看>>
h5+ hbuilder ios提示语修改
查看>>
单例模式的5种实现方式,以及在多线程环境下5种创建单例模式的效率
查看>>
oracle取前几行|中间几行|后几行
查看>>
16.1 Tomcat介绍
查看>>
QuickBI助你成为分析师——数据源FAQ小结
查看>>
十周三次课
查看>>
S/4HANA服务订单Service Order的批量创建
查看>>
2008 AD 复制有防火墙要开什么端口
查看>>
IT服务管理中的知识库建设
查看>>
【Lucene】Lucene通过CustomScoreQuery实现自定义评分
查看>>
linux 内核网络,数据接收流程图
查看>>
我的友情链接
查看>>
在windows下与linux虚拟机进行文件共享
查看>>