Codeforces Round #203 (Div. 2)

本蒟蒻总是那么渣渣 混在Div.2 哭了……昨天又是……看完题目小搞一下 然后提前睡觉去了……不过我现在貌似都没把题目看完==

 Problem A:很水的一题,原本以为是二分答案,后来发现连二分答案都不要。读入时确定枚举的上界和下界,然后枚举一下结束。

Problem B:一般CF的算法会比我想得简单,所以果断用了dfs。一切都很美好,不过挂在了pretest 10 超时。其实也不是大问题,对于第二个问题一开始用的是字符串储存,但其实字符串操作很耗时间,改成数组,仅在完成第一问后,再次从正解起始处再次dfs出第二问即可。

 Problem C:看起来好像很厉害的样子……其实吧 也不难。最基础的想法,找到炸弹——取炸弹——回家——砰 根据样例分析一下 想法很OK。由于题目里要求路径上不能有炸弹,所以很容易想到画圆,根据以(0,0)为圆心所画圆的半径升序(其实也就是距离),肯定可以保证符合题意,然后根据最初的想法,一个一个处理就好了。需要注意的是,这T一共有35个test,qsort必须随机化,不随机化=pass7 随机化=AC 可见还是随机化的qsort比较牛叉。还有就是如果不用randomize的话,随机出来的数都一样,约为括号内的数的一半,但还是比(l+r) div 2快;如果用的话,程序速度不确定,目前来看比不用的略慢,但也可以A。

还有吧,可以看出 Div.2 的T比较基础,但是T好在可以把一些容易忽视的东西放大。

剩下的等本渣渣看完题再说吧……(不过为什么我觉得有点普及组的感觉=_=)

 1 program ta;
 2 var
 3  n,m,i,j,up,down:integer;
 4  a,b:array [1..100] of integer;
 5  f:boolean;
 6 begin
 7  readln(n,m);
 8  up:=maxint;down:=0;
 9  for i:=1 to n do begin
10   read(a[i]);
11   if a[i]>down then down:=a[i];
12  end;
13  readln;
14  for i:=1 to m do begin
15   read(b[i]);
16   if b[i]<up then up:=b[i];
17  end;
18  if up<down then writeln(-1)
19  else begin
20   f:=false;
21   for i:=down to up-1 do begin
22    for j:=1 to n do
23     if a[j]*2<=i then begin;writeln(i);f:=true;break;end;
24    if f then break;
25   end;
26   if not(f) then writeln(-1);
27  end;
28 end.
Problem A
 1 program tb;
 2 var
 3  ans,max,n,temp,i,j:longint;
 4  t:array [1..100000] of integer;
 5  a,c:array [1..100000] of longint;
 6 procedure dfs(x:longint);
 7 begin
 8  while x<>0 do begin
 9   if c[x]>1 then exit;
10   inc(temp);
11   if temp>max then begin;max:=temp;ans:=i;end;
12   x:=a[x];
13  end;
14 end;
15 begin
16  readln(n);
17  fillchar(c,sizeof(c),0);
18  for i:=1 to n do
19   read(t[i]);
20  readln;
21  for i:=1 to n do begin
22   read(a[i]);
23   if a[i]>0 then inc(c[a[i]]);
24  end;
25  max:=0;
26  for i:=1 to n do
27   if t[i]=1 then begin
28    temp:=0;
29    dfs(i);
30   end;
31  writeln(max);
32  i:=ans;j:=0;
33  while (i<>0) and (j<max) do begin
34   inc(j);c[j]:=i;
35   i:=a[i];
36  end;
37  for i:=max downto 1 do write(c[i],' ');
38  writeln;
39 end.
Problem B
program tc;
type
 point=record
  x,y:int64;
  dis:double;
 end;
var
 ans,n,i:longint;
 g:Array [1..100000] of point;
procedure qsort(l,r:longint);
var
 i,j:longint;
 mid:double;
 t:point;
begin
 i:=l;j:=r;mid:=g[l+random(r-l+1)].dis;
 repeat
  while (g[i].dis<mid) do inc(i);
  while (mid<g[j].dis) do dec(j);
  if i<=j then begin
   t:=g[i];g[i]:=g[j];g[j]:=t;
   inc(i);dec(j);
  end;
 until i>j;
 if l<j then qsort(l,j);
 if i<r then qsort(i,r);
end;
begin
 readln(n);
 ans:=0;
 for i:=1 to n do
  with g[i] do begin
   readln(x,y);dis:=sqrt(sqr(x)+sqr(y));
   if (x<>0) and (y<>0) then inc(ans,6) else inc(ans,4);
  end;
 writeln(ans);
 qsort(1,n);
 for i:=1 to n do
  with g[i] do begin
   if x>0 then writeln(1,' ',x,' R')
   else
   if x<0 then writeln(1,' ',-x,' L');
   if y>0 then writeln(1,' ',y,' U')
   else
   if y<0 then writeln(1,' ',-y,' D');
   writeln(2);
   if x>0 then writeln(1,' ',x,' L')
   else
   if x<0 then writeln(1,' ',-x,' R');
   if y>0 then writeln(1,' ',y,' D')
   else
   if y<0 then writeln(1,' ',-y,' U');
   writeln(3);
  end;
end.
Problem C

 

 

posted @ 2013-10-02 11:02  lcj2018  阅读(213)  评论(0编辑  收藏  举报