【比赛链接】

点击打开链接

【题解】

Problem A Word Correction【字符串】

不用多说了吧,字符串的基本操作

Problem B  Run for your prize【贪心】

我们可以将这个数轴一分为二,小于等于500000的由第一个人领,否则由第二个人领

Problem C Constructing tests【贪心】【数学】

首先我们发现 : N^2 - (N / M)^2 = x (N/M向下取整)

然后我们算出N的上下界,发现: sqrt(x+1)<=N<=sqrt(3/4*x)  (sqrt是开根号的意思)

所以我们可以枚举N,算出M

Problem D Buy a ticket【最短路】

首先想到可以跑N遍最短路

但是很显然,这样会超时,那么我们该如何优化呢?

我们不妨先建一个原点,将原点与每个城市连边,权值为在这个城市开演唱会的价格ai,然后再将城市与城市之间连边,

但是每条路径上的权值要乘2,因为是往返的费用

我们发现,只要对这个图跑一遍最短路,就得出了答案。

注意N最大10^5,SPFA不能过,要用dijkstra+堆优化

代码 :

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAXN = * 1e5; LL i,N,M;
LL dist[MAXN+],a[MAXN+],b[MAXN+],c[MAXN+],w[MAXN+],vis[MAXN+];
vector< pair<LL,LL> > E[MAXN+]; template <typename T> inline void read(T &x) {
LL f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = x * + c - '';
x *= f;
} template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
} template <typename T> inline void writeln(T x) {
write(x);
puts("");
} inline void dijkstra(LL st) {
LL i,x,to,cost;
priority_queue< pair<LL,LL> > q;
for (i = ; i <= N; i++) dist[i] = LONG_LONG_MAX;
q.push(make_pair(,st));
dist[st] = ;
memset(vis,,sizeof(vis));
while (!q.empty()) {
x = q.top().second; q.pop();
if (vis[x]) continue;
vis[x] = ;
for (i = ; i < E[x].size(); i++) {
to = E[x][i].first;
cost = E[x][i].second;
if (dist[x] + cost < dist[to]) {
dist[to] = dist[x] + cost;
q.push(make_pair(-dist[to],to));
}
}
}
} int main() { read(N); read(M);
for (i = ; i <= M; i++) {
read(a[i]); read(b[i]); read(w[i]);
E[a[i]].push_back(make_pair(b[i],w[i]*));
E[b[i]].push_back(make_pair(a[i],w[i]*));
}
for (i = ; i <= N; i++) {
read(c[i]);
E[N+].push_back(make_pair(i,c[i]));
}
dijkstra(N+);
for (i = ; i <= N; i++) {
if (i == ) write(dist[i]);
else { putchar(' '); write(dist[i]); }
}
puts(""); return ;
}

【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解的更多相关文章

  1. Educational Codeforces Round 38 (Rated for Div. 2) C

    C. Constructing Tests time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. Educational Codeforces Round 38 (Rated for Div. 2)

    这场打了小号 A. Word Correction time limit per test 1 second memory limit per test 256 megabytes input sta ...

  3. Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)

    题:https://codeforces.com/contest/1257/problem/E 题意:给定3个数组,可行操作:每个数都可以跳到另外俩个数组中去,实行多步操作后使三个数组拼接起来形成升序 ...

  4. Educational Codeforces Round 92 (Rated for Div. 2) B、C题解

    TAT 第一场codeforces B. Array Walk #暴力 #贪心 题目链接 题意 有\(a1, a2, ..., an\) 个格子(每个格子有各自分数),最初为1号格(初始分数为\(a1 ...

  5. Educational Codeforces Round 116 (Rated for Div. 2), problem: (C) Banknotes

    传送门 Problem - C - Codeforces 题目 题目重点内容手打翻译:(欢迎批评指正) 在柏林, 使用着n套不同的货币(banknotes).第i个货币面额为10ai 元,货币的第一种 ...

  6. Educational Codeforces Round 96 (Rated for Div. 2) E. String Reversal 题解(思维+逆序对)

    题目链接 题目大意 给你一个长度为n的字符串,可以交换相邻两个元素,使得这个字符串翻转,求最少多少种次数改变 题目思路 如果要求数组排序所需要的冒泡次数,那其实就是逆序对 这个也差不多,但是如果是相同 ...

  7. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  9. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

随机推荐

  1. android Containers控件

    1.RadioGroup 一组单选框容器 2.ListView 3.GridView 4.ExpandableListView 可折叠列表 5.ScrollView 上下滚动条 6.Horizonta ...

  2. CMDB资产管理系统的数据表设计

    Server表: asset = models.OneToOneField('Asset') 主机名(hostname) sn号(sn) 制造商(manufacture) 系统(os_platform ...

  3. Currency Exchange(最短路)

    poj—— 1860 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 29851   Ac ...

  4. linux find grep 查找命令

    原文:fhqdddddd.blog.163.com/blog/static/186991542012417105729415/ find 1.作用 find命令的作用是在目录中搜索文件,它的使用权限是 ...

  5. CSS 居中 可随着浏览器变大变小而居中

    关键代码: 外部DIV使用: text-align:center; 内部DIV使用: margin-left:auto;margin-right:auto 例: <div style=" ...

  6. VS2017不能生成Database Unit Test项目

    问题描述: VS2017生成Database Unit Test项目时,报出如下错误,但该项目在VS2015中能正常生成: 主要是因为下面两个程序集找不到引用: Microsoft.Data.Tool ...

  7. JS那些事儿——Gulp的入门使用

    前言 新人使用gulp的一个记录. 首先对于第一个新事物,我会问gulp这是什么? 答:gulp是一个自动化构建工具,它可以做一些自动化的任务,比如: 检查Javascript 编译Sass(或Les ...

  8. jmeter.properties控制聚合报告的用户响应时间设置和smmary results

    jmeter.properties的配置Summariser控制输出Summary Results,可以显式rt和tps等信息 Aggregate Report配置可以控制聚合报告的内容,控制90%用 ...

  9. Mqtt协议IOS端移植3

    ServerMqFramework.h #import "MqttFramework.h" @interface ServerMqFramework : MqttFramework ...

  10. Android-studio 连接真机 调试weex项目

    1.选择项目 platforms  /  android 2.创建虚拟机(AVD) (1)点击 AVD Manager (2) 点击  Create Virtual Device 最后发现 CPU 不 ...