CH Round #48 - Streaming #3 (NOIP模拟赛Day1)

A.数三角形

题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛Day1)/数三角形

题解:暴力枚举三元组,判断是否共线即可,用叉积

代码:

 1 type cp=record
 2      x,y:double;
 3      end;
 4 var a:array[0..200] of cp;
 5     i,j,k,n,ans:longint;
 6 function cross(a,b,c:cp):double;
 7  begin
 8    cross:=(b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
 9  end;
10 procedure init;
11  begin
12    readln(n);
13    for i:=1 to n do readln(a[i].x,a[i].y);
14  end;
15 procedure main;
16  begin
17    ans:=0;
18    for i:=1 to n do
19     for j:=i+1 to n do
20      for k:=j+1 to n do
21       begin
22       if cross(a[i],a[j],a[k])<>0 then inc(ans);
23       end;
24    writeln(ans);
25  end;
26 
27 begin
28   init;
29   main;
30 end.                         
View Code

B.4和7

题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛Day1)/4和7

题解:这类似于vijosp1002过河,那题是当距离超过105时缩到105,但我取20也过了,现在也不知道为什么要压。。。

        这一道题比较好做,因为只有4和7两个数,由裴蜀定理我们知道 (4,7)=1 所以仅有4和7是可以组合出所有的整数的,

        但这题必须保证4和7的系数都必须是非负的。

        所以我们从前面开始尝试,看看能发现什么规律。

        发现前面有的可以4和7组合出来 比如15,但有的就组合不出来,如13

        进一步我们又发现当x>=18时,就都可以组合出来了。我们详细的证明一下:

        i) x mod 4=0 直接全用4即可

        ii)  x mod 4=1 我们可以用3个7,剩下的全用4,因为这样的数最小是21

        iii)x mod 4=2 我们用2个7,剩下的全用4

        iiii)x mod 4=3 我们用1个7,剩下的全用4

       这样就可以了当相邻两个有药的位置距离相隔≥18时就将它看作18,这样是没有问题的。

       考场上没有处理刚开始的边界情况,WA了30分

代码:

 1 var v,a,b,c,f:array[-100..2000000] of int64;
 2     i,n:longint;
 3     ans,m,tmp:int64;
 4 function max(x,y:int64):int64;
 5  begin
 6  if x>y then exit(x) else exit(y);
 7  end;
 8 procedure sort(l,r:longint);
 9  var i,j,x,y:longint;
10  begin
11  i:=l;j:=r;x:=b[(i+j)>>1];
12  repeat
13   while b[i]<x do inc(i);
14   while b[j]>x do dec(j);
15   if i<=j then
16    begin
17    y:=a[i];a[i]:=a[j];a[j]:=y;
18    y:=b[i];b[i]:=b[j];b[j]:=y;
19    inc(i);dec(j);
20    end;
21  until i>j;
22  if i<r then sort(i,r);
23  if j>l then sort(l,j);
24  end;
25 procedure init;
26  begin
27   readln(n,m);
28   for i:=1 to n do readln(a[i],b[i]);
29   sort(1,n);
30  end;
31 procedure main;
32  begin
33   b[0]:=0;c[0]:=0;
34   for i:=1 to n do
35    if b[i]-b[i-1]>=18 then c[i]:=c[i-1]+18
36    else c[i]:=c[i-1]+b[i]-b[i-1];
37   fillchar(v,sizeof(v),0);
38   for i:=1 to n do inc(v[c[i]],a[i]);
39   f[0]:=1;
40   for i:=4 to c[n] do
41    begin
42    tmp:=max(f[i-4],f[i-7]);
43    if tmp=0 then continue;
44    f[i]:=tmp+v[i];
45    end;
46   ans:=0;
47   for i:=0 to c[n] do ans:=max(ans,f[i]);
48   writeln(ans-1);
49  end;
50 
51 begin
52   init;
53   main;
54 end.     
View Code

C.反射镜

题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛Day1)/反射镜

题解:考场上没想到什么好的算法,于是打了200行的暴力。。。幸亏没写跪,骗到60分,结果标程竟然那么短。。。

代码:

1.暴力

  1 type cp=record
  2      x,y,id,idx:longint;
  3      z:char;
  4      end;
  5 var a,b:array[0..150000] of cp;
  6     now,dir,n,m,i,x,y,tmp:longint;
  7     c:array[0..150000] of longint;
  8     dist,t:int64;
  9     ans:cp;
 10 
 11 function cmp1(a,b:cp):boolean;
 12  begin
 13  if a.x=b.x then exit(a.y<b.y) else exit(a.x<b.x);
 14  end;
 15 function cmp2(a,b:cp):boolean;
 16  begin
 17  if a.y=b.y then exit(a.x<b.x) else exit(a.y<b.y);
 18  end;
 19 procedure sort1(l,r:longint);
 20  var i,j:longint;x,y:cp;
 21  begin
 22  i:=l;j:=r;x:=a[(i+j)>>1];
 23  repeat
 24   while cmp1(a[i],x) do inc(i);
 25   while cmp1(x,a[j]) do dec(j);
 26   if i<=j then
 27    begin
 28    y:=a[i];a[i]:=a[j];a[j]:=y;
 29    inc(i);dec(j);
 30    end;
 31  until i>j;
 32  if i<r then sort1(i,r);
 33  if j>l then sort1(l,j);
 34  end;
 35 procedure sort2(l,r:longint);
 36  var i,j:longint;x,y:cp;
 37  begin
 38  i:=l;j:=r;x:=b[(i+j)>>1];
 39  repeat
 40   while cmp2(b[i],x) do inc(i);
 41   while cmp2(x,b[j]) do dec(j);
 42   if i<=j then
 43    begin
 44    y:=b[i];b[i]:=b[j];b[j]:=y;
 45    inc(i);dec(j);
 46    end;
 47  until i>j;
 48  if i<r then sort2(i,r);
 49  if j>l then sort2(l,j);
 50  end;
 51 procedure init;
 52  begin
 53  readln(n,m,t);
 54  for i:=1 to n do begin readln(a[i].x,a[i].y,a[i].z,a[i].z);a[i].id:=i;end;
 55  for i:=1 to n do b[i]:=a[i];
 56  sort1(1,n);
 57  sort2(1,n);
 58  for i:=1 to n do c[a[i].id]:=i;
 59  for i:=1 to n do b[i].idx:=c[b[i].id];
 60  for i:=1 to n do c[b[i].id]:=i;
 61  for i:=1 to n do a[i].idx:=c[a[i].id];
 62  a[n+1].x:=maxlongint;a[n+1].y:=maxlongint;
 63  a[0].x:=maxlongint;a[0].y:=maxlongint;
 64  b[n+1]:=a[n+1];b[0]:=a[0];
 65  end;
 66 procedure main;
 67  begin
 68   x:=0;y:=0;
 69   for i:=1 to n do if (b[i].y=0) and (b[i].x>0) then begin now:=i;break;end;
 70   if now=0 then
 71      begin
 72      writeln(t,' ',0);exit;
 73      end;
 74   dir:=3;dist:=b[now].x;ans:=b[now];
 75   while true do
 76    begin
 77     if dir=3 then
 78      begin
 79       if b[now].z='/' then
 80         begin
 81         dir:=2;
 82         now:=b[now].idx;
 83         tmp:=now+1;
 84         if a[tmp].x<>a[now].x then break;
 85         if dist+abs(a[tmp].y-a[now].y)>t then break
 86         else inc(dist,abs(a[tmp].y-a[now].y));
 87         now:=tmp;ans:=a[now];
 88         end
 89       else
 90         begin
 91          dir:=4;
 92          now:=b[now].idx;
 93          tmp:=now-1;
 94          if a[tmp].x<>a[tmp].x then break;
 95          if dist+abs(a[tmp].y-a[now].y)>t then break
 96          else inc(dist,abs(a[tmp].y-a[now].y));
 97          now:=tmp;ans:=a[now];
 98         end;
 99      end;
100     if dir=2 then
101       begin
102        if a[now].z='/' then
103          begin
104           dir:=3;
105           now:=a[now].idx;
106           tmp:=now+1;
107           if b[tmp].y<>b[now].y then break;
108           if dist+abs(b[tmp].x-b[now].x)>t then break
109           else inc(dist,abs(b[tmp].x-b[now].x));
110           now:=tmp;ans:=b[now];
111          end
112        else
113          begin
114           dir:=1;
115           now:=a[now].idx;
116           tmp:=now-1;
117           if b[tmp].y<>b[now].y then break;
118           if dist+abs(b[tmp].x-b[now].x)>t then break
119           else inc(dist,abs(b[tmp].x-b[now].x));
120           now:=tmp;ans:=b[now];
121          end;
122       end;
123     if dir=1 then
124        begin
125         if b[now].z='/' then
126           begin
127            dir:=4;
128            now:=b[now].idx;
129            tmp:=now-1;
130            if a[tmp].x<>a[now].x then break;
131            if dist+abs(a[tmp].y-a[now].y)>t then break
132            else inc(dist,abs(a[tmp].y-a[now].y));
133            now:=tmp;ans:=a[now];
134           end
135         else
136           begin
137            dir:=2;
138            now:=b[now].idx;
139            tmp:=now+1;
140            if a[tmp].x<>a[now].x then break;
141            if dist+abs(a[tmp].y-a[now].y)>t then break
142            else inc(dist,abs(a[tmp].y-a[now].y));
143            now:=tmp;ans:=a[now];
144           end;
145        end;
146     if dir=4 then
147       begin
148        if a[now].z='/' then
149          begin
150           dir:=1;
151           now:=a[now].idx;
152           tmp:=now-1;
153           if b[tmp].y<>b[now].y then break;
154           if dist+abs(b[tmp].x-b[now].x)>t then break
155           else inc(dist,abs(b[tmp].x-b[now].x));
156           now:=tmp;ans:=b[now];
157          end
158        else
159          begin
160           dir:=3;
161           now:=a[now].idx;
162           tmp:=now+1;
163           if b[tmp].y<>b[now].y then break;
164           if dist+abs(b[tmp].x-b[now].x)>t then break
165            else inc(dist,abs(b[tmp].x-b[now].x));
166           now:=tmp;ans:=b[now];
167          end;
168       end;
169    end;
170  if dir=1 then writeln(ans.x-(t-dist),' ',ans.y);
171  if dir=2 then writeln(ans.x,' ',ans.y+(t-dist));
172  if dir=3 then writeln(ans.x+(t-dist),' ',ans.y);
173  if dir=4 then writeln(ans.x,' ',ans.y-(t-dist));
174  end;
175 procedure spj;
176  begin
177  if a[1].y<>0 then writeln(t,' ',0)
178  else if a[1].x<0 then writeln(t,' ',0)
179  else if a[1].z='/' then writeln(a[1].x,' ',t-a[1].x)
180  else writeln(a[1].x,' ',a[1].x-t);
181  end;
182 
183 begin
184   init;
185   if n=1 then spj else main;
186 end.                            
View Code

2.正解

  1 #include <cstdio>
  2 #include <cstring>
  3 #include <algorithm>
  4 #define UU 0
  5 #define LL 1
  6 #define DD 2
  7 #define RR 3
  8 //LeftTurn = 1
  9 //RightTurn = 3
 10 const int dx[4] = {0, -1, 0, 1};
 11 const int dy[4] = {1, 0, -1, 0};
 12 #define f(x, y, z) for(int x = (y); x <= (z); ++x)
 13 #define f2(x, y, z) for(int x = (y), asdf = (z); x <= asdf; ++x)
 14 using std::min;
 15 using std::abs;
 16 
 17 int N; long long T;
 18 struct mir{int x, y; long long dr;} xm[400086], ym[400086];
 19 inline bool byx(const mir &a, const mir &b){
 20     return a.x < b.x || (a.x == b.x && a.y < b.y);
 21 }
 22 inline bool byy(const mir &a, const mir &b){
 23     return a.y < b.y || (a.y == b.y && a.x < b.x);
 24 }
 25 inline bool operator ==(const mir &a, const mir &b){
 26     return a.x == b.x && a.y == b.y;
 27 }
 28 
 29 inline mir *findxless(const mir a){
 30     int l = 0, r = N + 1;
 31     while(l < r){
 32         int m = ((l + r) >> 1) + 1;
 33         if(xm[m] == a) return xm + m;
 34         else if(byx(xm[m], a)) l = m; else r = m - 1;
 35     }
 36     if(l < 1 || l > N || xm[l].x != a.x) return NULL;
 37     return xm + l;
 38 }
 39 inline mir *findxmore(const mir a){
 40     int l = 0, r = N + 1;
 41     while(l < r){
 42         int m = (l + r) >> 1;
 43         if(xm[m] == a) return xm + m;
 44         else if(byx(a, xm[m])) r = m; else l = m + 1;
 45     }
 46     if(l < 1 || l > N || xm[l].x != a.x) return NULL;
 47     return xm + l;
 48 }
 49 inline mir *findyless(const mir a){
 50     int l = 0, r = N + 1;
 51     while(l < r){
 52         int m = ((l + r) >> 1) + 1;
 53         if(ym[m] == a) return ym + m;
 54         else if(byy(ym[m], a)) l = m; else r = m - 1;
 55     }
 56     if(l < 1 || l > N || ym[l].y != a.y) return NULL;
 57     return ym + l;
 58 }
 59 inline mir *findymore(const mir a){
 60     int l = 0, r = N + 1;
 61     while(l < r){
 62         int m = (l + r) >> 1;
 63         if(ym[m] == a) return ym + m;
 64         else if(byy(a, ym[m])) r = m; else l = m + 1;
 65     }
 66     if(l < 1 || l > N || ym[l].y != a.y) return NULL;
 67     return ym + l;
 68 }
 69 
 70 int main(){
 71     scanf("%d%*d%I64d", &N, &T); long long iT = T;
 72     f(i, 1, N){
 73         int cx, cy; char buf[4];
 74         scanf("%d%d%s", &cx, &cy, buf);
 75         xm[i].x = ym[i].x = cx;
 76         xm[i].y = ym[i].y = cy;
 77         if(buf[0] == '/'){
 78             xm[i].dr = 3; ym[i].dr = 1;
 79         }else{
 80             xm[i].dr = 1; ym[i].dr = 3;
 81         }
 82     }
 83     xm[0] = (mir) {-1000000008, -1000000008, 0};
 84     ym[0] = (mir) {-1000000008, -1000000008, 0};
 85     xm[N + 1] = (mir) {1000000008, 1000000008, 0};
 86     ym[N + 1] = (mir) {1000000008, 1000000008, 0};
 87     std::sort(xm + 1, xm + N + 1, byx);
 88     std::sort(ym + 1, ym + N + 1, byy);
 89     int cx = 0, cy = 0, cr = RR;
 90     for(;;){
 91         // printf("C %d %d = %d\n", cx, cy, cr);
 92         mir *res;
 93         if(cr == UU) res = findxmore((mir) {cx, cy + 1});
 94         else if(cr == LL) res = findyless((mir) {cx - 1, cy});
 95         else if(cr == DD) res = findxless((mir) {cx, cy - 1});
 96         else res = findymore((mir) {cx + 1, cy});
 97         if(res){
 98             if(cy == 0 && res->y == 0 && cx < 0 && res->x > 0) T %= (iT - T - cx);
 99             int dis = abs(res->x - cx) + abs(res->y - cy);
100             if(dis < T){
101                 cx = res->x; cy = res->y; cr = (cr + res->dr) % 4; T -= (long long) dis;
102             }else{
103                 printf("%I64d %I64d\n", (long long) cx + T * (long long) dx[cr], (long long) cy + T * (long long) dy[cr]);
104                 return 0;
105             }
106         }else{
107             printf("%I64d %I64d\n", (long long) cx + T * (long long) dx[cr], (long long) cy + T * (long long) dy[cr]);
108             return 0;
109         }
110     }
111     return 0;
112 }
View Code

 

       

posted @ 2014-08-16 13:15  ZYF-ZYF  Views(429)  Comments(0Edit  收藏  举报