首先吐槽一下这套题。。。为什么EF全是图论QAQ

过了ABCD四个题。。。F的并查集死磕了好久。。。

不过似乎rank还算乐观。。。(因为ABC都是一次过的QAQ)

Problem A:

啥都不想说QAQ。。。

代码如下:

 var a,b,c,d,max,min,ans:longint;
begin
readln(a,b,c);
max:=a;
min:=a;
if (b>max) then max:=b;
if (c>max) then max:=c;
if (b<min) then min:=b;
if (c<min) then min:=c;
d:=a+b+c-max-min;
ans:=abs(a-d)+abs(b-d)+abs(c-d);
writeln(ans);
end.

Problem B:

统计字符串的题,注意一下括号里面的各种细节,以及各种单词统计的处理就可以了。

代码如下:

 var n,i,j,max,ans,now:longint;
flag:boolean;
ch:array[..] of char;
function flagg(x:char):boolean;
begin
if (<=ord(x)) and (ord(x)<=+) then exit(true);
if (<=ord(x)) and (ord(x)<=+) then exit(true);
exit(false);
end;
begin
readln(n);
for i:= to n do
read(ch[i]);
readln;
max:=;
ans:=;
flag:=true;
i:=;
now:=;
while (i<=n) do
begin
if flagg(ch[i]) then inc(now);
if not(flagg(ch[i])) then
begin
if flag then
begin
if (now>max) then max:=now;
now:=;
end
else
begin
if (now>) then inc(ans);
now:=;
end;
end;
if (ch[i]='(') then flag:=false;
if (ch[i]=')') then flag:=true;
inc(i);
end;
if (now>) then
begin
if not(flag) then inc(ans);
if flag and(now>max) then max:=now;
end;
writeln(max,' ',ans);
end.

Problem C:

这题的题意需要好好理解一下。。。

首先需要看出,第一个答案就是n div m,

接下来方案只需要按照类似贪心来模拟就可以了,注意一下边界的细节。

代码如下:

 var n,m,i,j,ans,ans1:longint;
a,flag,flag1,anss:array[..] of longint;
begin
readln(n,m);
fillchar(a,sizeof(a),);
for i:= to n do
read(a[i]);
readln;
write(n div m,' ');
ans:=n div m;
fillchar(flag,sizeof(flag),);
for i:= to n do
if (a[i]<=m) then inc(flag[a[i]]);
ans1:=;
for i:= to m do
if (flag[i]<ans) then ans1:=ans1+ans-flag[i];
writeln(ans1);
fillchar(flag1,sizeof(flag1),);
fillchar(anss,sizeof(anss),);
for i:= to n do
begin
if (a[i]<=m) then
begin
if (flag1[a[i]]<ans) then
begin
inc(flag1[a[i]]);
anss[i]:=a[i];
end;
end;
end;
i:=;
j:=;
while (j<=m) and (flag1[j]>=ans) do inc(j);
while (i<=n) do
begin
if (anss[i]=) then
begin
if (j<>m+) then
begin
anss[i]:=j;
inc(flag1[j]);
while (j<=m) and (flag1[j]>=ans) do inc(j);
end else anss[i]:=a[i];
end;
inc(i);
end;
for i:= to n do
write(anss[i],' ');
writeln;
end.

Problem D:

这题题意似乎也没写好QAQ

这题其实就是一个DFS就可以了,由于最开始的内陆湖个数大于等于k,所以直接贪心处较小的那几个内陆湖面积,然后加起来就可以了。

注意细节,比如周围一圈算海洋,不属于内陆湖。

代码如下:

 const tx:array[..] of longint=(,,,-);
ty:array[..] of longint=(,-,,);
var n,m,k,i,j,tot,now,ans,ii,jj:longint;
flag:boolean;
ch:array[..,..] of char;
vis:array[..,..] of boolean;
r:array[..,..] of longint;
area,b:array[..] of longint;
procedure qsort(lx,rx:longint);
var i,j,m,t:longint;
begin
i:=lx;
j:=rx;
m:=area[(i+j) div ];
repeat
while (area[i]<m) do inc(i);
while (area[j]>m) do dec(j);
if (i<=j) then
begin
t:=area[i];
area[i]:=area[j];
area[j]:=t;
t:=b[i];
b[i]:=b[j];
b[j]:=t;
inc(i);
dec(j);
end;
until (i>j);
if (i<rx) then qsort(i,rx);
if (j>lx) then qsort(lx,j);
end;
procedure tryit(x,y:longint);
var i,j,a,b:longint;
begin
r[x,y]:=tot+;
vis[x,y]:=true;
inc(now);
if (x=) or (x=n) or (y=) or (y=m) then flag:=false;
for i:= to do
begin
a:=x+tx[i];
b:=y+ty[i];
if (<=a) and (a<=n) and (<=b) and (b<=m) then
if not(vis[a,b]) and (ch[a,b]='.') then tryit(a,b);
end;
end;
procedure trycolor(t:longint);
var i,j:longint;
begin
for i:= to n do
for j:= to m do
if (r[i,j]=t) then ch[i,j]:='*';
end;
begin
readln(n,m,k);
for i:= to n do
begin
for j:= to m do
read(ch[i,j]);
readln;
end;
fillchar(area,sizeof(area),);
fillchar(b,sizeof(b),);
fillchar(r,sizeof(r),);
tot:=;
fillchar(vis,sizeof(vis),false);
for i:= to n- do
for j:= to m- do
if (ch[i,j]='.') and not(vis[i,j]) then
begin
now:=;
flag:=true;
tryit(i,j);
if flag then
begin
inc(tot);
area[tot]:=now;
end
else
begin
for ii:= to n do
for jj:= to m do
if (r[ii,jj]=tot+) then r[ii,jj]:=;
end;
end;
for i:= to tot do
b[i]:=i;
qsort(,tot);
ans:=;
for i:= to tot-k do
begin
trycolor(b[i]);
ans:=ans+area[i];
end;
writeln(ans);
for i:= to n do
begin
for j:= to m do
write(ch[i,j]);
writeln;
end;
end.

Problem E:

这是一道欧拉混合回路。。。

首先,你需要大胆猜出结论,就是所有度数为偶数的最后都可以满足条件。

然后跑欧拉回路迭代构造方案就可以了。(很传统的做法)

代码如下:

 var t,l,m,n,i,j,ans,u,v,tot:longint;
deg:array[..] of longint;
r:array[..,..] of longint;
vis:array[..] of boolean;
next,last,other:array[..] of longint;
procedure insert(x,y:longint);
begin
inc(tot);
next[tot]:=last[x];
last[x]:=tot;
other[tot]:=y;
inc(tot);
next[tot]:=last[y];
last[y]:=tot;
other[tot]:=x;
end;
procedure dfs(x:longint);
var i,j:longint;
begin
i:=last[x];
while (i>) do
begin
if not(vis[i div ]) then
begin
vis[i div ]:=true;
dfs(other[i]);
if (i div <=m) then
begin
r[i div ,]:=x;
r[i div ,]:=other[i];
end;
end;
i:=next[i];
end;
end;
begin
readln(t);
for l:= to t do
begin
readln(n,m);
fillchar(vis,sizeof(vis),false);
fillchar(deg,sizeof(deg),);
fillchar(r,sizeof(r),false);
fillchar(next,sizeof(next),);
fillchar(last,sizeof(last),);
fillchar(other,sizeof(other),);
tot:=;
ans:=;
for i:= to m do
begin
readln(u,v);
insert(u,v);
inc(deg[u]);
inc(deg[v]);
end;
for i:= to n do
if (deg[i] mod =) then insert(i,n+) else inc(ans);
for i:= to n do
dfs(i);
writeln(ans);
for i:= to m do
writeln(r[i,],' ',r[i,]);
end;
end.

Problem F:

本场最细节的题目了。。。

首先,这是一道并查集。。。

然后就是一堆细节了,各种地方需要注意。(比如在第一次联通之后,在清除关系之前需要保留数据)

具体细节都可以看代码。

代码如下:

 var n,m,s,t,ds,dt,i,j,now1,now2,now3,now4,x:longint;
a,b,father,fatherr,cs,ct:array[..] of longint;
flag1,flag2,flag,vis:array[..] of boolean;
flagg,flagt:boolean;
function tryit(i:longint):longint;
var k,t,p:longint;
begin
k:=i;
while (father[k]<>k) do k:=father[k];
t:=i;
while (t<>k) do
begin
p:=father[t];
father[t]:=k;
t:=p;
end;
exit(k);
end;
function tryit1(i:longint):longint;
var k,t,p:longint;
begin
k:=i;
while (fatherr[k]<>k) do k:=fatherr[k];
t:=i;
while (t<>k) do
begin
p:=fatherr[t];
fatherr[t]:=k;
t:=p;
end;
exit(k);
end;
procedure mdf(a1,b1:longint);
var i,j:longint;
begin
i:=tryit(a1);
j:=tryit(b1);
if (i<>j) then father[j]:=i;
end;
begin
readln(n,m);
fillchar(a,sizeof(a),);
fillchar(b,sizeof(b),);
fillchar(cs,sizeof(cs),);
fillchar(ct,sizeof(ct),);
for i:= to m do
readln(a[i],b[i]);
readln(s,t,ds,dt);
for i:= to n do
father[i]:=i;
flagg:=false;
for i:= to m do
begin
if (a[i]<>s) and (a[i]<>t) and (b[i]<>s) and (b[i]<>t) then mdf(a[i],b[i]);
if (a[i]=s) and (b[i]=t) then flagg:=true;
if (a[i]=t) and (b[i]=s) then flagg:=true;
end;
fillchar(flag1,sizeof(flag1),false);
fillchar(flag2,sizeof(flag2),false);
fillchar(flag,sizeof(flag),false);
for i:= to n do
if (i<>s) and (i<>t) then flag[tryit(i)]:=true;
for i:= to m do
begin
if (a[i]=s) then
begin
flag1[tryit(b[i])]:=true;
cs[tryit(b[i])]:=b[i];
end;
if (b[i]=s) then
begin
flag1[tryit(a[i])]:=true;
cs[tryit(a[i])]:=a[i];
end;
if (a[i]=t) then
begin
flag2[tryit(b[i])]:=true;
ct[tryit(b[i])]:=b[i];
end;
if (b[i]=t) then
begin
flag2[tryit(a[i])]:=true;
ct[tryit(a[i])]:=a[i];
end;
end;
now1:=;
now2:=;
now3:=;
now4:=;
for i:= to n do
if (i<>s) and (i<>t) and flag[i] then
begin
if flag1[i] and not(flag2[i]) then inc(now1);
if flag2[i] and not(flag1[i]) then inc(now2);
if flag1[i] and flag2[i] then inc(now3);
if not(flag1[i]) and not(flag2[i]) then inc(now4);
end;
if (now3>) and ((now1+now2+now3+>ds+dt) or (now1+>ds) or (now2+>dt)) then
begin
writeln('No');
halt;
end
else if (now3=) and (not(flagg) or (now1+now2+now3+>ds+dt) or (now1+>ds) or (now2+>dt)) then
begin
writeln('No');
halt;
end
else
begin
writeln('Yes');
fatherr:=father;
fillchar(father,sizeof(father),);
for i:= to n do
father[i]:=i;
flagt:=true;
for i:= to n do
if (i<>s) and (i<>t) and flag[i] then
begin
if flag1[i] and not(flag2[i]) then
begin
dec(ds);
writeln(s,' ',cs[tryit1(i)]);
mdf(s,i);
end
else if flag2[i] and not(flag1[i]) then
begin
dec(dt);
writeln(t,' ',ct[tryit1(i)]);
mdf(t,i);
end;
end;
for i:= to n do
if (i<>s) and (i<>t) and flag[i] then
begin
if flag1[i] and flag2[i] then
begin
if flagt and (ds>) and (dt>) then
begin
dec(ds);
dec(dt);
writeln(s,' ',cs[tryit1(i)]);
writeln(t,' ',ct[tryit1(i)]);
mdf(s,i);
mdf(t,i);
flagt:=false;
end else
if (ds>) then
begin
dec(ds);
writeln(s,' ',cs[tryit1(i)]);
mdf(s,i);
end else
begin
dec(dt);
writeln(t,' ',ct[tryit1(i)]);
mdf(t,i);
end;
end;
end;
if flagg and flagt then
begin
dec(ds);
dec(dt);
writeln(s,' ',t);
mdf(s,t);
end;
for i:= to m do
begin
if (tryit(a[i])<>tryit(b[i])) and (a[i]<>s) and (b[i]<>s) and (a[i]<>t) and (b[i]<>t) then
begin
writeln(a[i],' ',b[i]);
mdf(a[i],b[i]);
end
end;
end;
end.

完结撒花!~~~

codeforces round375(div.2)题解的更多相关文章

  1. codeforces round373(div.2) 题解

    这一把打得还算过得去... 最大问题在于A题细节被卡了好久...连续被hack两次... B题是个规律题...C题也是一个细节题...D由于不明原因标程错了被删掉了...E是个线段树套矩阵... 考试 ...

  2. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  3. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  4. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  5. Educational Codeforces Round 65 (Rated for Div. 2)题解

    Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...

  6. Educational Codeforces Round 64 (Rated for Div. 2)题解

    Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...

  7. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  8. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  9. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

随机推荐

  1. centos 6 安装VMware Tools

    开启虚拟机的centos系统, 在虚拟机工具栏点击 “虚拟机”=>VMwareTools安装,  centos系统内的桌面会有一个VMware Tools的驱动光驱, 双击打开后,有一个tar. ...

  2. linux系统监控工具glances

    glances linux系统自带了很多系统性能监控工具,如top,vmstat,iftop等等,还有一款监视工具glances,它能把其他几个监控的指标都集于一身.Glances是一个相对比较新的系 ...

  3. CSS-标准盒模型 & 怪异盒模型

    CSS中Box model分类 CSS中Box model是分为两种:: W3C标准 和 IE标准盒子模型. 大多数浏览器采用W3C标准模型,而IE中则采用Microsoft自己的标准. 怪异模式是“ ...

  4. Postgres安装详解

    PG安装 一.基础包的安装(yum源的配置,可以采用光盘挂载,及ftp yum源,针对外网环境忽略此步): yum -y install wget tcpdump glibc libgcc gcc g ...

  5. [Hdu1693]Eat the Trees(插头DP)

    Description 题意:在n*m(1<=N, M<=11 )的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃完所有的树,求有多少种方法. Solution 插头DP ...

  6. python单元测试用例

    demo1.py #!/usr/bin/python # encoding: utf-8 def hello(): print "i am in demo1" def add(x, ...

  7. OpenCV学习笔记(十) 直方图操作

    直方图计算 直方图可以统计的不仅仅是颜色灰度, 它可以统计任何图像特征 (如 梯度, 方向等等).直方图的一些具体细节: dims: 需要统计的特征的数目, 在上例中, dims = 1 因为我们仅仅 ...

  8. 3 - JVM随笔分类(gc.log ,VisualVM插件介绍,VisualVM远程连接方式介绍)

    gc.log 354.2 KB 对于对应用的监控上可以使用Jdk自带的VisualVM来做可视化监控,可以查看当前服务应用进程的堆大小的走向,以及类的加载数量等,除此之外,VisualVM可以支持很多 ...

  9. 引用其他头文件时出现这种错误,莫名其妙,error C2065: “ColorMatrix”: 未声明的标识符

    今天做项目时,直接拷贝了另一个工程里的头文件和源文件,然后运行时就出现这种问题,莫名其妙,在原程序里运行一点问题就没有,但是在新工程里就是error. >e:\c++\button_fly2\b ...

  10. Docker与CTF

    Docker与CTF 主要是用来搭建环境,漏洞环境,CTF比赛题目复现. docker你可以把它理解为一个vmware. iamges:vmware需要的iso镜像 container:vmware运 ...