Codeforces Round #513 (rated, Div. 1 + Div. 2)
前记
眼看他起高楼;眼看他宴宾客;眼看他楼坍了。
比赛历程
开考前一分钟还在慌里慌张地订正上午考试题目。
“诶这个数位dp哪里见了鬼了???”瞥了眼时间,无奈而迅速地关去所有其他窗口,临时打了一个缺省源。
A. Phone Numbers
那么就是模拟。
#include<bits/stdc++.h> int n,x;
char s[]; int read()
{
char ch = getchar();
int num = ;
bool fl = ;
for (; !isdigit(ch); ch=getchar())
if (ch=='-') fl = ;
for (; isdigit(ch); ch=getchar())
num = (num<<)+(num<<)+ch-;
if (fl) num = -num;
return num;
}
int main()
{
n = read();
scanf("%s",s);
for (int i=; i<n; i++)
if (s[i]=='') x++;
printf("%d\n",std::min(x, n/));
return ;
}
B. Maximum Sum of Digits
结论题。构造尽可能多的999……
#include<bits/stdc++.h>
typedef long long ll; ll n,num; long long read()
{
char ch = getchar();
long long num = ;
bool fl = ;
for (; !isdigit(ch); ch=getchar())
if (ch=='-') fl = ;
for (; isdigit(ch); ch=getchar())
num = (num<<)+(num<<)+ch-;
if (fl) num = -num;
return num;
}
ll calc(ll x)
{
ll ret=;
for (; x; x/=) ret += x%;
return ret;
}
int main()
{
n = read(), num = ;
while (num < n) num = num*+;
num /= ;
printf("%lld\n",calc(num)+calc(n-num));
return ;
}
C. Maximum Subrectangle
有点意思的题:找一个面积最大,权值和小于lim的矩阵。但是这个矩阵有个特殊性质:它不是没有规律地给定,而是由两个数列相乘构造而来。n<=2000.
做法一:
先枚举一个维,将这个维所有的段长和元素和都存下来,然后sort一下。另一维枚举,二分寻找最大能够匹配的段。
时间复杂度$O(n^2log_2n)$
做法二:
然而上面一个做法的浪费在于存下所有的段。注意到这个决策是单调的,对于长度相同的段,只有元素和最小的是有用的。那么对于两个维,都记录这个最小值。最后分别枚举两维的长度时直接匹配。
时间复杂度$O(n^2)$
#include<bits/stdc++.h>
const int maxn = ; struct node
{
int a,b;
bool operator < (node x) const
{
if (a < x.a) return a < x.a;
return b < x.b;
}
}sv[];
int a[maxn],b[maxn],n,m,lim;
int sa[maxn],sb[maxn];
int mna[maxn],mnb[maxn];
int cnt,ans; int read()
{
char ch = getchar();
int num = ;
bool fl = ;
for (; !isdigit(ch); ch=getchar())
if (ch=='-') fl = ;
for (; isdigit(ch); ch=getchar())
num = (num<<)+(num<<)+ch-;
if (fl) num = -num;
return num;
}
int main()
{
memset(mna, 0x3f3f3f3f, sizeof mna);
memset(mnb, 0x3f3f3f3f, sizeof mnb);
n = read(), m = read();
for (int i=; i<=n; i++) a[i] = read(), sa[i] = sa[i-]+a[i];
for (int i=; i<=m; i++) b[i] = read(), sb[i] = sb[i-]+b[i];
lim = read();
for (int i=; i<=n; i++)
for (int j=i; j<=n; j++)
mna[j-i+] = std::min(mna[j-i+], sa[j]-sa[i-]);
for (int i=; i<=m; i++)
for (int j=i; j<=m; j++)
mnb[j-i+] = std::min(mnb[j-i+], sb[j]-sb[i-]);
for (int i=; i<=n; i++)
for (int j=; j<=m; j++)
if (1ll*mna[i]*mnb[j] <= 1ll*lim)
ans = std::max(ans, i*j);
printf("%d\n",ans);
return ;
}
D. Social Circles
开场时候原本就打算手速D的,又恰巧总榜上D被秒掉了。于是弃了BC就去看D……
想了好久也没有什么靠谱做法,这时t老师6分钟就写完了D,瞬间心态崩坏。
想啊想啊,是个贪心?图论?然而一点没往结论题方向想。
没办法只能转回头去做C。脑子里一团浆糊,什么也想不进去。
最后是等到XCW在1:09大力猜结论过了pretest机房才大队人马过D。
大致题意:有n个人,每个人要求自己左边有li张空椅子;右边有ri张空椅子。可以把不同的人任意分组。问最小需要的总椅子数量。
结论是:这些人的左右手要求是可以互换的。那么就是排序之后取max。
好像现在官方题解还没出来?那么这个结论我也没法证明……
#include<bits/stdc++.h>
const int maxn = ; int n,a[maxn],b[maxn];
long long ans; int main()
{
scanf("%d",&n);
for (int i=; i<=n; i++) scanf("%d",&a[i]);
for (int i=; i<=n; i++) scanf("%d",&b[i]);
std::sort(a+, a+n+);
std::sort(b+, b+n+);
for (int i=; i<=n; i++) ans += std::max(a[i], b[i]);
printf("%lld\n",ans);
return ;
}
E. Sergey and Subway
花CD的时间太久了……E题题意直接去问同学了。
然而刚开始一段时间把题意理解错了。
大致题意:现在有一颗树,边权均为1。每次操作将原树上距离为2的点,在新树上连接一条边权为1的边。进行操作直到不能再操作为止。询问新树两两点对距离和。
首先是结论:原树上长度为$d$的路径,在新树上长度变为$\frac{d+1}{2}(向下取整)$。
这个比较容易理解:对于长度为2的路径,长度变为1;长度为1的路径,长度不变;然后任意一条路径都可以视作由2、1的路径拼接而成。
第一感觉是点分?但是一看时间不大对了直接去求助t老师了。
t老师:不用点分……一开始我写了一个很复杂的上下dp。这个题超傻逼的,只要枚举边计算贡献。然后计奇数路径条数。深度奇偶性不同的就是奇数路径。
哇好有道理的样子哦。想了想就开始码(然而中间还码错了点小细节耽搁一会),然后就愉快地过掉了。(但是毕竟还是手速太慢,E题最后只有1008的分)
#include<bits/stdc++.h>
const int maxn = ; long long ans;
int n,tot[maxn],dep[maxn],sum[];
int edges[maxn<<],nxt[maxn<<],head[maxn],edgeTot; int read()
{
char ch = getchar();
int num = ;
bool fl = ;
for (; !isdigit(ch); ch=getchar())
if (ch=='-') fl = ;
for (; isdigit(ch); ch=getchar())
num = (num<<)+(num<<)+ch-;
if (fl) num = -num;
return num;
}
void addedge(int u, int v)
{
edges[++edgeTot] = v, nxt[edgeTot] = head[u], head[u] = edgeTot;
edges[++edgeTot] = u, nxt[edgeTot] = head[v], head[v] = edgeTot;
}
void dfs(int x, int fa)
{
tot[x] = , dep[x] = dep[fa]+, sum[dep[x]&]++;
for (int i=head[x]; i!=-; i=nxt[i])
{
int v = edges[i];
if (v!=fa){
dfs(v, x);
tot[x] += tot[v];
long long t = 1ll*tot[v]*(n-tot[v]);
ans += t;
}
}
}
int main()
{
memset(head, -, sizeof head);
n = read();
for (int i=; i<n; i++) addedge(read(), read());
dfs(, );
ans += 1ll*sum[]*sum[];
printf("%lld\n",ans/);
return ;
}
xor则是发现了点分FFT的写法,恰巧以前度教出过一道类似的题,于是机房大队人马搬来自己代码争先恐后地过了pretest。
【后话:除了我和xor其他人都FST了;反正WA、RE、TLE全齐了】
后记
哎,暑假一共就打了两场,打得还非常差。现在也不过是一直在expert徘徊。
反观同级甚至初中的大佬,已经不是Grandmaster就是Master最差Candiate Master了。
考试时候依然起伏不定,思维发挥也没有达到所期望的那种地步。
即便是往年今日,zx2003也早就上紫了啊!
“How BAD do you want it?”

Codeforces Round #513 (rated, Div. 1 + Div. 2)的更多相关文章
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
随机推荐
- 图像像素灰度内插(Matlab实现)
常用的像素灰度内插法:最近邻元法.双线性内插法.三次内插法 %%像素灰度内插 factor = 0.75;%缩放比 u = 0.6;v = 0.7; itp1 = uint8(zeros(ceil(h ...
- Glassfish 4 修改server.log 等配置
如果所示:
- java.exe is valid, but is for a machine type other than the current machine
java.exe is valid, but is for a machine type other than the current machine jdk版本不一致问题,在32位机器上使用64位的 ...
- 后台任务利器之Hangfire
后台任务利器之Hangfire 一.简述 Hangfire作为一款高人气且容易上手的分布式后台执行服务,支持多种数据库.在.net core的环境中,由Core自带的DI管理着生命周期,免去了在NF4 ...
- 关于float和double类型能表示的数据范围和精度分析
来自教材<计算机组成原理>p16 float:6--7位 double:15--16位 意思就是double类型的数据,你确实能表达出很大的数字,但是其只有15位是精确的. 1.计算机中, ...
- Windows7&IIS7.5部署Discuz全攻略
组长说在内网部署一个论坛,这可难不倒我,装个Discuz嘛.部署环境就一台普通的PC,四核i3,Windows7.这就开搞了. 准备工作 系统是Windows 7 专业版,自带IIS7.5(家庭版不带 ...
- [原]Maven项目编译后classes文件中没有.xml问题
在做spring+mybatiss时,自动扫描都配置正确了,却在运行时出现了如下错误.后来查看target/classes/.../dao/文件夹下,发现只有mapper的class文件,而没有xml ...
- css position 定位模式
定位 定位模式: static relative absolute fixed 边偏移 :top bottom left right 一般的定位必须要有定位模式以及边偏移 static 静态定位 默 ...
- 洛谷 P2983 [USACO10FEB]购买巧克力Chocolate Buying
购买巧克力Chocolate Buying 乍一看以为是背包,然后交了一个感觉没错的背包上去. #include <iostream> #include <cstdio> #i ...
- ubuntu和window之间如何共享文件
参考网上的自己动手实现共享文件: 1.打开虚拟机进入ubuntu系统,先安装增强功能包 2.安装完重启虚拟机后,在window下创建一个专门用来共享的文件夹 3.切换到ubuntu系统,在设备的共享文 ...