A - The Third Cup is Free

水。

 #include<bits/stdc++.h>

 using namespace std;

 const int maxn = 1e5 + ;

 int n;
int arr[maxn]; int main()
{
int t;
scanf("%d", &t);
for(int cas = ; cas <= t; ++cas)
{
scanf("%d", &n);
for(int i = ; i <= n; ++i) scanf("%d", arr + i);
sort(arr + , arr + + n);
int ans = ;
int cnt = ;
for(int i = n; i >= ; --i)
{
cnt++;
if(cnt == )
{
arr[i] = ;
cnt = ;
}
ans += arr[i];
}
printf("Case #%d: %d\n", cas, ans);
}
return ;
}

B - Wash

题意:有n个洗衣机,有m个烘干机,要洗L件衣服,最后一件衣服洗完的最少时间

思路:将n个洗衣机扩展成L个洗衣机,将m个烘干机扩展成L个烘干机,那么贪心分配即可。

即用时最少的洗衣机和用时最多的烘干机配对,扩展的话,将n个洗衣机都进堆,然后依次取出,再丢进去,丢进去的时候加上它的洗衣时间即可。

 #include<bits/stdc++.h>

 using namespace std;

 typedef long long ll;
const int maxn = 1e6 + ; struct node{
ll cost, now;
node(){}
node(ll cost, ll now): cost(cost), now(now){}
bool operator < (const node & b) const
{
return now > b.now;
}
}; int l, n, m;
ll arr[maxn]; int main()
{
int t;
scanf("%d", &t);
for(int cas = ; cas <= t; ++cas)
{
scanf("%d %d %d", &l, &n, &m);
priority_queue<node>q1, q2;
for(int i = ; i <= n; ++i)
{
int x;
scanf("%d", &x);
q1.push(node(x, x));
}
for(int i = ; i <= m; ++i)
{
int x;
scanf("%d", &x);
q2.push(node(x, x));
}
for(int i = ; i <= l; ++i)
{
node tmp = q1.top();
q1.pop();
arr[i] = tmp.now;
tmp.now += tmp.cost;
q1.push(tmp);
}
ll ans = ;
for(int i = l; i >= ; --i)
{
node tmp = q2.top();
q2.pop();
ans = max(ans, tmp.now + arr[i]);
tmp.now += tmp.cost;
q2.push(tmp);
}
printf("Case #%d: %lld\n", cas, ans);
}
return ;
}

C - Mr.Panda and Survey

留坑。

D - Game Leader

留坑。

E - Problem Buyer

题意:出题人有n道题目,主办方需要m道不同难度题目,出题人的题目有一个难度范围,如果主办方需要买k道题目,那么出题人就从n道题目中随机选取k道给主办方,主办方要使得不论出题人如何给出k道题都能满足他的要求,求最小的k

思路:我们先考虑主办方只需要一道题的情况,答案显然是不符合那道题的其他题目个数+1

那么再考虑推广到m的情况,将区间排序,并且将题目难度也排序,从左至右用优先队列维护里面的区间是否满足,那么不满足的个数就是n - 优先队列里面的元素个数   那么显然对于这道题,至少要取 不满足个数+1  再考虑一个区间只能给一个题目,那么每次扫过去的时候pop出一个即可, $那么我们求出最大的x_i + 1 即可   x_i表示不满足第i个题目的区间有多少个$

 #include<bits/stdc++.h>

 using namespace std;

 const int maxn = 1e5 + ;

 struct node{
int l, r;
node(){}
node(int l, int r):l(l), r(r){}
bool operator < (const node &b)const
{
return r > b.r;
}
}arr[maxn]; int cmp(node a, node b)
{
if(a.l == b.l) return a.r > b.r;
else return a.l < b.l;
} int n, m;
int brr[maxn]; int main()
{
int t;
scanf("%d", &t);
for(int cas = ; cas <= t; ++cas)
{
scanf("%d %d", &n, &m);
for(int i = ; i <= n; ++i) scanf("%d %d", &arr[i].l, &arr[i].r);
for(int i = ; i <= m; ++i) scanf("%d", brr + i);
sort(arr + , arr + + n, cmp);
sort(brr + , brr + + m);
priority_queue<node>q;
int ans = ;
int j = ;
for(int i = ; i <= m; ++i)
{
while(j <= n && arr[j].l <= brr[i]) q.push(arr[j++]);
while(!q.empty() && q.top().r < brr[i]) q.pop();
int tmp = q.size();
ans = max(ans, n - tmp + );
if(ans > n) break;
q.pop();
}
if(ans > n) printf("Case #%d: IMPOSSIBLE!\n", cas);
else printf("Case #%d: %d\n", cas, ans);
}
return ;
}

F - Periodical Cicadas

留坑。

G - Pandaland

题意:给出一张图,找一个最小环(边权和最小)

思路:枚举每一条边为两个端点跑最短路,如果跑的通即存在环,更新答案即可。

但是正解应该是:

求最小生成树,每次枚举非树边,就是树上两个距离+边权

 #include <bits/stdc++.h>
using namespace std; #define ll long long
#define INFLL 0x3f3f3f3f3f3f3f3f
#define N 8010
#define pii pair <int, int>
int t, n, m;
map <pii, int> mp; struct Edge
{
struct node
{
int to, nx, w, vis;
node() {}
node(int to, int nx, int w, int vis = ) : to(to), nx(nx), w(w), vis(vis) {}
}a[N << ];
int head[N], pos;
void init() { memset(head, , sizeof head); pos = -; }
void add(int u, int v, int w)
{
a[++pos] = node(v, head[u], w); head[u] = pos;
a[++pos] = node(u, head[v], w); head[v] = pos;
}
}G;
#define erp(u) for (int it = G.head[u], v = G.a[it].to, w = G.a[it].w; it; it = G.a[it].nx, v = G.a[it].to, w = G.a[it].w) int Hash(int x, int y)
{
if (mp.find(pii(x, y)) == mp.end()) mp[pii(x, y)] = ++n;
return mp[pii(x, y)];
} struct node
{
int to; ll w;
node () {}
node (int to, ll w) : to(to), w(w) {}
bool operator < (const node &r) const
{
return w > r.w;
}
}; ll dist[N]; bool used[N]; void Dijkstra(int st, int ed)
{
for (int i = ; i <= n; ++i) dist[i] = INFLL, used[i] = false;
priority_queue <node> q; q.emplace(st, ); dist[st] = ;
while (!q.empty())
{
int u = q.top().to; q.pop();
if(u == ed) return ;
if (used[u]) continue;
used[u] = ;
erp(u) if (G.a[it].vis)
{
if (!used[v] && dist[v] > dist[u] + w)
{
dist[v] = dist[u] + w;
q.emplace(v, dist[v]);
}
}
}
} int main()
{
scanf("%d", &t);
for (int kase = ; kase <= t; ++kase)
{
printf("Case #%d: ", kase);
scanf("%d", &m);
mp.clear(); n = ; G.init();
for (int i = , x[], y[], w, u, v; i <= m; ++i)
{
for (int j = ; j < ; ++j) scanf("%d%d", x + j, y + j);
scanf("%d", &w); u = Hash(x[], y[]); v = Hash(x[], y[]);
G.add(u, v, w);
}
ll res = INFLL;
for (int i = ; i <= m - ; ++i)
{
G.a[ * i].vis = ; G.a[ * i + ].vis = ;
int u = G.a[ * i].to, v = G.a[ * i + ].to;
Dijkstra(u, v);
res = min(res, G.a[ * i].w + dist[v]);
G.a[ * i].vis = ; G.a[ * i + ].vis = ;
}
if (res == INFLL) res = ;
printf("%lld\n", res);
}
return ;
}

正解:

 #include <bits/stdc++.h>
using namespace std; #define ll long long
#define INFLL 0x3f3f3f3f3f3f3f3f
#define N 8010
#define pii pair <int, int>
int t, n, m;
map <pii, int> mp; struct Gragh
{
struct node
{
int to, nx, w;
node() {}
node(int to, int nx, int w) : to(to), nx(nx), w(w){}
}a[N << ];
int head[N], pos;
void init() { memset(head, , sizeof head); pos = ; }
void add(int u, int v, int w)
{
a[++pos] = node(v, head[u], w); head[u] = pos;
a[++pos] = node(u, head[v], w); head[v] = pos;
}
}G;
#define erp(u) for (int it = G.head[u], v = G.a[it].to, w = G.a[it].w; it; it = G.a[it].nx, v = G.a[it].to, w = G.a[it].w) struct Edge
{
int u, v, vis; ll w;
Edge() {}
Edge(int u, int v, ll w, int vis = ) : u(u), v(v), w(w), vis(vis) {}
bool operator < (const Edge &r) const { return w < r.w; }
}edge[N]; int Hash(int x, int y)
{
if (mp.find(pii(x, y)) == mp.end()) mp[pii(x, y)] = ++n;
return mp[pii(x, y)];
} int pre[N];
int find(int x) { return pre[x] == ? x : pre[x] = find(pre[x]); } void Kruskal()
{
sort(edge + , edge + + m);
for (int i = ; i <= m; ++i)
{
int u = edge[i].u, v = edge[i].v; ll w = edge[i].w;
int fu = find(u), fv = find(v);
if (fu == fv) continue;
pre[fu] = fv;
G.add(u, v, w);
edge[i].vis = ;
}
} int fa[N], sze[N], son[N], top[N], deep[N], rt[N]; ll dis[N];
void DFS(int u, int root)
{
sze[u] = ;
rt[u] = root;
erp(u) if (v != fa[u])
{
fa[v] = u;
deep[v] = deep[u] + ;
dis[v] = dis[u] + w;
DFS(v, root); sze[u] += sze[v];
if (!son[u] || sze[v] > sze[son[u]]) son[u] = v;
}
} void getpos(int u, int sp)
{
top[u] = sp;
if (!son[u]) return;
getpos(son[u], sp);
erp(u) if (v != fa[u] && v != son[u])
getpos(v, v);
} int lca(int u, int v)
{
while (top[u] != top[v])
{
if (deep[top[u]] < deep[top[v]]) swap(u, v);
u = fa[top[u]];
}
if (deep[u] > deep[v]) swap(u, v);
return u;
} void Init()
{
mp.clear(); n = ; G.init();
memset(pre, , sizeof pre);
memset(son, , sizeof son);
memset(fa, , sizeof fa);
} int main()
{
scanf("%d", &t);
for (int kase = ; kase <= t; ++kase)
{
Init();
printf("Case #%d: ", kase);
scanf("%d", &m);
for (int i = , x[], y[], w, u, v; i <= m; ++i)
{
for (int j = ; j < ; ++j) scanf("%d%d", x + j, y + j);
scanf("%d", &w); u = Hash(x[], y[]); v = Hash(x[], y[]);
edge[i] = Edge(u, v, w);
} Kruskal();
for (int i = ; i <= n; ++i) if (!fa[i])
{
fa[i] = i; dis[i] = ; deep[i] = ;
DFS(i, i); getpos(i, i);
}
ll res = INFLL;
for (int i = , u, v, w; i <= m; ++i) if (!edge[i].vis)
{
u = edge[i].u, v = edge[i].v, w = edge[i].w;
if (rt[u] != rt[v]) continue;
res = min(res, dis[u] + dis[v] - * dis[lca(u, v)] + w);
}
if (res == INFLL) res = ;
printf("%lld\n", res);
}
return ;
}

H - Engineer Assignment

题意:有b个工程,m个工程师,每个工程师只能分配给一个工程,每个工程师会一些学科,每门工程需要一些学科,一个工程只有当它需要的学科中至少有一个分配到的工程师会,它才能够完成,求如何分配工程师使得完成的工程最多

思路:考虑$s_i$表示一个工程可以完成的工程师组合

$有转移方程 dp[i][j] = max(dp[i][j], dp[i - 1][j - s]) $

$i 表示 第i个工程,j 表示二进制状态 然后 dp 即可$

 #include <bits/stdc++.h>
using namespace std; int t, n, m;
vector <int> v[], a[], b[];
int cnt[], dp[][]; bool ok(int x)
{
for (auto it : a[x]) if (!cnt[it])
return false;
return true;
} int main()
{
scanf("%d", &t);
for (int kase = ; kase <= t; ++kase)
{
printf("Case #%d: ", kase);
scanf("%d%d", &n, &m);
for (int i = , t; i <= n; ++i)
{
scanf("%d", &t);
a[i].clear();
for (int j = , x; j <= t; ++j)
{
scanf("%d", &x);
a[i].push_back(x);
}
}
for (int i = , t; i <= m; ++i)
{
scanf("%d", &t); b[i].clear();
for (int j = , x; j <= t; ++j)
{
scanf("%d", &x);
b[i].push_back(x);
}
}
for (int i = ; i <= n; ++i)
{
v[i].clear();
for (int j = ; j < ( << m); ++j)
{
memset(cnt, , sizeof cnt);
for (int k = ; k < ; ++k) if (( << k) & j) for (auto it : b[k + ])
cnt[it] = ;
if (ok(i)) v[i].push_back(j);
}
}
int res = ;
memset(dp, , sizeof dp);
for (int i = ; i <= n; ++i)
{
for (int j = ; j < ( << m); ++j) for (auto it : v[i]) if ((j & it) == it)
dp[i][j] = max(dp[i][j], dp[i - ][j - it] + ), res = max(res, dp[i][j]);
for (int j = ; j < ( << m); ++j) dp[i][j] = max(dp[i][j], dp[i - ][j]);
}
printf("%d\n", res);
}
return ;
}

I - Mr. Panda and Crystal

题意:有n种物品,有的物品可以直接生成,有的可以不生成,需要合成,会给出一个合成方程,每种物品有价值,有一个容量为m的背包,求装下哪些物品使得价值最大

思路:最短路求出每个物品的最小生成成本,再做完全背包即可。

 #include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 40010
#define INFLL 0x3f3f3f3f3f3f3f3f
#define pii pair <int, int>
int t, m, n, k;
ll v[N], dp[N]; struct EXP
{
int to;
vector <pii> v;
}ex[N];
vector <int> G[N]; struct node
{
int to; ll w;
node () {}
node (int to, ll w) : to(to), w(w) {}
bool operator < (const node &r) const { return w > r.w; }
}; ll dist[N]; bool used[N];
void Dijkstra()
{
priority_queue <node> q;
for (int i = ; i <= n; ++i) if (dist[i] != INFLL) q.emplace(i, dist[i]);
while (!q.empty())
{
int u = q.top().to; q.pop();
if (used[u]) continue;
used[u] = ;
for (auto it : G[u])
{
ll tmp = ;
for (auto it2 : ex[it].v)
{
int to = it2.first, w = it2.second;
if (dist[to] == INFLL)
{
tmp = INFLL;
break;
}
else
tmp += dist[to] * w;
}
int v = ex[it].to;
if (!used[v] && dist[v] > tmp)
{
dist[v] = tmp;
q.emplace(v, dist[v]);
}
}
}
} int main()
{
scanf("%d", &t);
for (int kase = ; kase <= t; ++kase)
{
printf("Case #%d: ", kase);
scanf("%d%d%d", &m, &n, &k);
for (int i = ; i <= n; ++i) dist[i] = INFLL, used[i] = ;
for (int i = , vis; i <= n; ++i)
{
scanf("%d", &vis); if (vis) scanf("%lld", dist + i);
scanf("%lld", v + i);
G[i].clear();
}
for (int i = , t; i <= k; ++i)
{
scanf("%d", &ex[i].to); ex[i].v.clear();
scanf("%d", &t);
for (int j = , x, y; j <= t; ++j)
{
scanf("%d%d", &x, &y);
ex[i].v.push_back(pii(x, y));
G[x].push_back(i);
}
}
Dijkstra();
memset(dp, , sizeof dp);
for (int i = ; i <= n; ++i)
{
for (int j = dist[i]; j <= m; ++j)
dp[j] = max(dp[j], dp[j - dist[i]] + v[i]);
}
printf("%lld\n", dp[m]);
}
return ;
}

J - Worried School

水。

 #include <bits/stdc++.h>
using namespace std; int t, g; string tar;
set <string> se;
string s[][]; void work()
{
for (int i = ; i <= ; ++i)
{
for (int j = ; j < ; ++j)
{
if (s[j][i] == tar) return;
se.insert(s[j][i]);
}
}
} void work2()
{
for (int i = ; i <= ; ++i)
{
if (s[][i] == tar) return;
se.insert(s[][i]);
}
} int main()
{
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
cin >> t;
for (int kase = ; kase <= t; ++kase)
{
cout << "Case #" << kase << ": ";
cin >> g >> tar;
se.clear();
for (int i = ; i < ; ++i) for (int j = ; j <= ; ++j) cin >> s[i][j];
work();
if (se.size() >= g)
{
cout << "0\n";
continue;
}
int res = g - (int)se.size();
work2();
if (se.size() < g) cout << "ADVANCED!\n";
else cout << max(, res) << "\n";
}
return ;
}

K - Lazors

留坑。

L - Daylight Saving Time

按题意模拟即可。

 #include <bits/stdc++.h>
using namespace std; struct node
{
int h, m, s;
node () {}
node (int h, int m, int s) : h(h), m(m), s(s) {}
}a;
int t, Year, Mon, Day;
int num[][] =
{
, , , , , , , , , , , , ,
, , , , , , , , , , , , ,
}; int ok(int x)
{
if ((x % == && x % != ) || x % == ) return ;
return ;
} int calc(int y, int m, int d)
{
int res = ;
for (int i = ; i < y; ++i)
res += + ok(i);
for (int i = ; i < m; ++i) res += num[ok(y)][i];
res += d;
return (res - ) % + ;
} int main()
{
scanf("%d", &t);
for (int kase = ; kase <= t; ++kase)
{
printf("Case #%d: ", kase);
scanf("%04d-%02d-%02d %02d:%02d:%02d", &Year, &Mon, &Day, &a.h, &a.m, &a.s);
if (Mon == )
{
int tar = - calc(Year, , );
if (Day == tar)
{
if (a.h == ) puts("Neither");
else if (a.h < ) puts("PST");
else puts("PDT");
}
else puts(Day < tar ? "PST" : "PDT");
}
else if (Mon == )
{
int tar = - calc(Year, , );
if (Day == tar)
{
if (a.h == ) puts("Both");
else if (a.h < ) puts("PDT");
else puts("PST");
}
else puts(Day < tar ? "PDT" : "PST");
}
else puts(Mon < ? "PST" : "PDT");
}
return ;
}

CCPC 2016-2017, Finals Solution的更多相关文章

  1. 【转】2016/2017 Web 开发者路线图

    链接:知乎 [点击查看大图] 原图来自LearnCodeAcademy最火的视频,learncode是YouTube上最火的Web开发教学频道,介绍包括HTML/CSS/JavaScript/Subl ...

  2. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)

    Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...

  3. CCPC 2017-2018, Finals Solution

    A - Dogs and Cages 水. #include <bits/stdc++.h> using namespace std; int t; double n; int main( ...

  4. [SinGuLaRiTy] COCI 2016~2017 #5

    [SinGuLaRiTy-1012] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 最近神犇喜欢考COCI...... 测试题目 对于所有的 ...

  5. 关于ECMAScript 2016, 2017, 和2018中新增功能(摘抄)

    ECMAScript 2016 1. Array.prototype.includes includes是数组上的简单实例方法,并有助于轻松查找某个项是否在Array中(包括NaN不像indexOf) ...

  6. SQL Server 2012/2016/2017 新增函数

    /************************************************************** SQL Server 2012 新增的函数 ************** ...

  7. ECMAScript 2016,2017 和 2018 中所有新功能的示例

    很难追踪 JavaScript(ECMAScript)中的新功能. 想找到有用的代码示例更加困难. 因此,在本文中,我将介绍 TC39 已完成 ES2016,ES2017 和 ES2018(最终草案) ...

  8. [转]ECMAScript 2016,2017 和 2018 中所有新功能的示例

    很难追踪 JavaScript(ECMAScript)中的新功能. 想找到有用的代码示例更加困难. 因此,在本文中,我将介绍 TC39 已完成 ES2016,ES2017 和 ES2018(最终草案) ...

  9. Mindjet MindManager 2016/2017 折腾记录

    https://community.mindjet.com/mindjet/topics/ensure-2017-64-bit-version-installation Mindmanager sho ...

随机推荐

  1. 单独使用 EHCache

    1. EHCache 的特点,是一个纯Java ,过程中(也可以理解成插入式)缓存实现,单独安装Ehcache ,需把ehcache-X.X.jar 和相关类库方到classpath中.如项目已安装了 ...

  2. 【RF库Collections测试】Get Dictionary Keys

    Name:Get Dictionary KeysSource:Collections <test library>Arguments:[ dictionary ]Returns `keys ...

  3. upper()

    upper() 用于把字符串中的小写字母转换成大写字母 In [1]: str = "Hello World" In [2]: str.upper() Out[2]: 'HELLO ...

  4. c#截取图片

    简单的保存数据流 <input name="upImg" style="width: 350px; height: 25px;" size="3 ...

  5. poj_1236 强连通分支

    题目大意 有N个学校,这些学校之间用一些单向边连接,若学校A连接到学校B(B不一定连接到A),那么给学校A发一套软件,则学校B也可以获得.现给出学校之间的连接关系,求出至少给几个学校分发软件,才能使得 ...

  6. 【mysql】查看版本的四种方法

    1:在终端下:mysql -V. 以下是代码片段: [test@login ~]$ mysql -V mysql Ver 14.7 Distrib 4.1.10a, for redhat-linux- ...

  7. 深入浅出Docker(四):Docker的集成测试部署之道

    1. 背景 敏捷开发已经流行了很长时间,如今有越来越多的企业开始践行敏捷开发所提倡的以人为中心.迭代.循序渐进的开发理念.在这样的场景下引入Docker技术,首要目的就是使用Docker提供的虚拟化方 ...

  8. console.log()的兼容性

    在别人那里看到的,兼容IE8-的console.log的实现,以前没想过. if(typeof console == "undefinde"){ this.console = {l ...

  9. 【黑金ZYNQ7000系列原创视频教程】03.体验FPGA里的ARM——裸机helloworld实验

    黑金论坛地址: http://www.heijin.org/forum.php?mod=viewthread&tid=36637&extra=page%3D1 爱奇艺地址: http: ...

  10. 证书:数字签名和验签&加密和解密

    用的是湖北省数字证书认证管理中心的签名和加密 1.带私钥的证书,即p12格式证书(后缀为.pfx) 2.不带私钥的证书,有多种格式,通常我们使用的是cer格式证书(后缀为.cer) 一. 1.什么是对 ...