首先吐槽一下这套题。。。为什么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. 驾考试题的json代码

    { "statusCode": "000000", "desc": "请求成功", "result" ...

  2. mysql基础,数据表的类型

  3. 二十六、MySQL 临时表

    MySQL 临时表 MySQL 临时表在我们需要保存一些临时数据时是非常有用的.临时表只在当前连接可见,当关闭连接时,Mysql会自动删除表并释放所有空间. 临时表在MySQL 3.23版本中添加,如 ...

  4. 麦子学院python开发全套完整无加密课程

    点击了解更多Python课程>>> 麦子学院python开发全套完整无加密课程 第一阶段:Python基础准备 1.Web前端开发之HTML+CSS基础入门 2.Javascript ...

  5. Nginx 配置支持 WAF

    WAF(Web Application Firewall),中文名叫做“Web应用防火墙” WAF的定义是这样的:Web应用防火墙是通过执行一系列针对HTTP/HTTPS的安全策略来专门为Web应用提 ...

  6. eclipse projectExplorer视图(以包的方式显示)与navigator视图切换(以文件夹的方式显示)及树状视图与平面视图的切换

    projectExplorer与navigator的切换 projectExplorer视图效果 想要此视图效果步骤如下: 分割------------------------------------ ...

  7. 多种方式实现依赖注入及使用注解定义bean

    构造注入 如何给构造方法中的参数注入方法呢如下 首先bean代码如下 package cn.pojo; public class Greeting { /** * 说的话 */ private Str ...

  8. 【PHP】foreach语法

    foreach 语法结构提供了遍历数组的简单方式.foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类型的变量,或者未初始化的变量将发出错误信息.有两种语法: foreach ($name ...

  9. Dialogue between Jack and Rose【jack 和 Rose的对话】

    Dialogue between Jack and Rose Rose : It's getting quiet. 越来越安静了 Jack : It's gonna take a couple of ...

  10. Codeforces Round #464 (Div. 2) C. Convenient For Everybody

    C. Convenient For Everybody time limit per test2 seconds memory limit per test256 megabytes Problem ...