CH Round #48 - Streaming #3 (NOIP模拟赛Day1)
A.数三角形
题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛Day1)/数三角形
题解:暴力枚举三元组,判断是否共线即可,用叉积
代码:
type cp=record
x,y:double;
end;
var a:array[..] of cp;
i,j,k,n,ans:longint;
function cross(a,b,c:cp):double;
begin
cross:=(b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
end;
procedure init;
begin
readln(n);
for i:= to n do readln(a[i].x,a[i].y);
end;
procedure main;
begin
ans:=;
for i:= to n do
for j:=i+ to n do
for k:=j+ to n do
begin
if cross(a[i],a[j],a[k])<> then inc(ans);
end;
writeln(ans);
end; begin
init;
main;
end.
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分
代码:
var v,a,b,c,f:array[-..] of int64;
i,n:longint;
ans,m,tmp:int64;
function max(x,y:int64):int64;
begin
if x>y then exit(x) else exit(y);
end;
procedure sort(l,r:longint);
var i,j,x,y:longint;
begin
i:=l;j:=r;x:=b[(i+j)>>];
repeat
while b[i]<x do inc(i);
while b[j]>x do dec(j);
if i<=j then
begin
y:=a[i];a[i]:=a[j];a[j]:=y;
y:=b[i];b[i]:=b[j];b[j]:=y;
inc(i);dec(j);
end;
until i>j;
if i<r then sort(i,r);
if j>l then sort(l,j);
end;
procedure init;
begin
readln(n,m);
for i:= to n do readln(a[i],b[i]);
sort(,n);
end;
procedure main;
begin
b[]:=;c[]:=;
for i:= to n do
if b[i]-b[i-]>= then c[i]:=c[i-]+
else c[i]:=c[i-]+b[i]-b[i-];
fillchar(v,sizeof(v),);
for i:= to n do inc(v[c[i]],a[i]);
f[]:=;
for i:= to c[n] do
begin
tmp:=max(f[i-],f[i-]);
if tmp= then continue;
f[i]:=tmp+v[i];
end;
ans:=;
for i:= to c[n] do ans:=max(ans,f[i]);
writeln(ans-);
end; begin
init;
main;
end.
C.反射镜
题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛Day1)/反射镜
题解:考场上没想到什么好的算法,于是打了200行的暴力。。。幸亏没写跪,骗到60分,结果标程竟然那么短。。。
代码:
1.暴力
type cp=record
x,y,id,idx:longint;
z:char;
end;
var a,b:array[..] of cp;
now,dir,n,m,i,x,y,tmp:longint;
c:array[..] of longint;
dist,t:int64;
ans:cp; function cmp1(a,b:cp):boolean;
begin
if a.x=b.x then exit(a.y<b.y) else exit(a.x<b.x);
end;
function cmp2(a,b:cp):boolean;
begin
if a.y=b.y then exit(a.x<b.x) else exit(a.y<b.y);
end;
procedure sort1(l,r:longint);
var i,j:longint;x,y:cp;
begin
i:=l;j:=r;x:=a[(i+j)>>];
repeat
while cmp1(a[i],x) do inc(i);
while cmp1(x,a[j]) do dec(j);
if i<=j then
begin
y:=a[i];a[i]:=a[j];a[j]:=y;
inc(i);dec(j);
end;
until i>j;
if i<r then sort1(i,r);
if j>l then sort1(l,j);
end;
procedure sort2(l,r:longint);
var i,j:longint;x,y:cp;
begin
i:=l;j:=r;x:=b[(i+j)>>];
repeat
while cmp2(b[i],x) do inc(i);
while cmp2(x,b[j]) do dec(j);
if i<=j then
begin
y:=b[i];b[i]:=b[j];b[j]:=y;
inc(i);dec(j);
end;
until i>j;
if i<r then sort2(i,r);
if j>l then sort2(l,j);
end;
procedure init;
begin
readln(n,m,t);
for i:= to n do begin readln(a[i].x,a[i].y,a[i].z,a[i].z);a[i].id:=i;end;
for i:= to n do b[i]:=a[i];
sort1(,n);
sort2(,n);
for i:= to n do c[a[i].id]:=i;
for i:= to n do b[i].idx:=c[b[i].id];
for i:= to n do c[b[i].id]:=i;
for i:= to n do a[i].idx:=c[a[i].id];
a[n+].x:=maxlongint;a[n+].y:=maxlongint;
a[].x:=maxlongint;a[].y:=maxlongint;
b[n+]:=a[n+];b[]:=a[];
end;
procedure main;
begin
x:=;y:=;
for i:= to n do if (b[i].y=) and (b[i].x>) then begin now:=i;break;end;
if now= then
begin
writeln(t,' ',);exit;
end;
dir:=;dist:=b[now].x;ans:=b[now];
while true do
begin
if dir= then
begin
if b[now].z='/' then
begin
dir:=;
now:=b[now].idx;
tmp:=now+;
if a[tmp].x<>a[now].x then break;
if dist+abs(a[tmp].y-a[now].y)>t then break
else inc(dist,abs(a[tmp].y-a[now].y));
now:=tmp;ans:=a[now];
end
else
begin
dir:=;
now:=b[now].idx;
tmp:=now-;
if a[tmp].x<>a[tmp].x then break;
if dist+abs(a[tmp].y-a[now].y)>t then break
else inc(dist,abs(a[tmp].y-a[now].y));
now:=tmp;ans:=a[now];
end;
end;
if dir= then
begin
if a[now].z='/' then
begin
dir:=;
now:=a[now].idx;
tmp:=now+;
if b[tmp].y<>b[now].y then break;
if dist+abs(b[tmp].x-b[now].x)>t then break
else inc(dist,abs(b[tmp].x-b[now].x));
now:=tmp;ans:=b[now];
end
else
begin
dir:=;
now:=a[now].idx;
tmp:=now-;
if b[tmp].y<>b[now].y then break;
if dist+abs(b[tmp].x-b[now].x)>t then break
else inc(dist,abs(b[tmp].x-b[now].x));
now:=tmp;ans:=b[now];
end;
end;
if dir= then
begin
if b[now].z='/' then
begin
dir:=;
now:=b[now].idx;
tmp:=now-;
if a[tmp].x<>a[now].x then break;
if dist+abs(a[tmp].y-a[now].y)>t then break
else inc(dist,abs(a[tmp].y-a[now].y));
now:=tmp;ans:=a[now];
end
else
begin
dir:=;
now:=b[now].idx;
tmp:=now+;
if a[tmp].x<>a[now].x then break;
if dist+abs(a[tmp].y-a[now].y)>t then break
else inc(dist,abs(a[tmp].y-a[now].y));
now:=tmp;ans:=a[now];
end;
end;
if dir= then
begin
if a[now].z='/' then
begin
dir:=;
now:=a[now].idx;
tmp:=now-;
if b[tmp].y<>b[now].y then break;
if dist+abs(b[tmp].x-b[now].x)>t then break
else inc(dist,abs(b[tmp].x-b[now].x));
now:=tmp;ans:=b[now];
end
else
begin
dir:=;
now:=a[now].idx;
tmp:=now+;
if b[tmp].y<>b[now].y then break;
if dist+abs(b[tmp].x-b[now].x)>t then break
else inc(dist,abs(b[tmp].x-b[now].x));
now:=tmp;ans:=b[now];
end;
end;
end;
if dir= then writeln(ans.x-(t-dist),' ',ans.y);
if dir= then writeln(ans.x,' ',ans.y+(t-dist));
if dir= then writeln(ans.x+(t-dist),' ',ans.y);
if dir= then writeln(ans.x,' ',ans.y-(t-dist));
end;
procedure spj;
begin
if a[].y<> then writeln(t,' ',)
else if a[].x< then writeln(t,' ',)
else if a[].z='/' then writeln(a[].x,' ',t-a[].x)
else writeln(a[].x,' ',a[].x-t);
end; begin
init;
if n= then spj else main;
end.
2.正解
#include <cstdio>
#include <cstring>
#include <algorithm>
#define UU 0
#define LL 1
#define DD 2
#define RR 3
//LeftTurn = 1
//RightTurn = 3
const int dx[] = {, -, , };
const int dy[] = {, , -, };
#define f(x, y, z) for(int x = (y); x <= (z); ++x)
#define f2(x, y, z) for(int x = (y), asdf = (z); x <= asdf; ++x)
using std::min;
using std::abs; int N; long long T;
struct mir{int x, y; long long dr;} xm[], ym[];
inline bool byx(const mir &a, const mir &b){
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
inline bool byy(const mir &a, const mir &b){
return a.y < b.y || (a.y == b.y && a.x < b.x);
}
inline bool operator ==(const mir &a, const mir &b){
return a.x == b.x && a.y == b.y;
} inline mir *findxless(const mir a){
int l = , r = N + ;
while(l < r){
int m = ((l + r) >> ) + ;
if(xm[m] == a) return xm + m;
else if(byx(xm[m], a)) l = m; else r = m - ;
}
if(l < || l > N || xm[l].x != a.x) return NULL;
return xm + l;
}
inline mir *findxmore(const mir a){
int l = , r = N + ;
while(l < r){
int m = (l + r) >> ;
if(xm[m] == a) return xm + m;
else if(byx(a, xm[m])) r = m; else l = m + ;
}
if(l < || l > N || xm[l].x != a.x) return NULL;
return xm + l;
}
inline mir *findyless(const mir a){
int l = , r = N + ;
while(l < r){
int m = ((l + r) >> ) + ;
if(ym[m] == a) return ym + m;
else if(byy(ym[m], a)) l = m; else r = m - ;
}
if(l < || l > N || ym[l].y != a.y) return NULL;
return ym + l;
}
inline mir *findymore(const mir a){
int l = , r = N + ;
while(l < r){
int m = (l + r) >> ;
if(ym[m] == a) return ym + m;
else if(byy(a, ym[m])) r = m; else l = m + ;
}
if(l < || l > N || ym[l].y != a.y) return NULL;
return ym + l;
} int main(){
scanf("%d%*d%I64d", &N, &T); long long iT = T;
f(i, , N){
int cx, cy; char buf[];
scanf("%d%d%s", &cx, &cy, buf);
xm[i].x = ym[i].x = cx;
xm[i].y = ym[i].y = cy;
if(buf[] == '/'){
xm[i].dr = ; ym[i].dr = ;
}else{
xm[i].dr = ; ym[i].dr = ;
}
}
xm[] = (mir) {-, -, };
ym[] = (mir) {-, -, };
xm[N + ] = (mir) {, , };
ym[N + ] = (mir) {, , };
std::sort(xm + , xm + N + , byx);
std::sort(ym + , ym + N + , byy);
int cx = , cy = , cr = RR;
for(;;){
// printf("C %d %d = %d\n", cx, cy, cr);
mir *res;
if(cr == UU) res = findxmore((mir) {cx, cy + });
else if(cr == LL) res = findyless((mir) {cx - , cy});
else if(cr == DD) res = findxless((mir) {cx, cy - });
else res = findymore((mir) {cx + , cy});
if(res){
if(cy == && res->y == && cx < && res->x > ) T %= (iT - T - cx);
int dis = abs(res->x - cx) + abs(res->y - cy);
if(dis < T){
cx = res->x; cy = res->y; cr = (cr + res->dr) % ; T -= (long long) dis;
}else{
printf("%I64d %I64d\n", (long long) cx + T * (long long) dx[cr], (long long) cy + T * (long long) dy[cr]);
return ;
}
}else{
printf("%I64d %I64d\n", (long long) cx + T * (long long) dx[cr], (long long) cy + T * (long long) dy[cr]);
return ;
}
}
return ;
}
CH Round #48 - Streaming #3 (NOIP模拟赛Day1)的更多相关文章
- CH Round #54 - Streaming #5 (NOIP模拟赛Day1)
A.珠 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2354%20-%20Streaming%20%235%20(NOIP模拟赛Day1)/珠 题解:sb题, ...
- CH Round #54 - Streaming #5 (NOIP模拟赛Day1)解题报告
最近参加了很多CH上的比赛呢~Rating--了..题目各种跪烂.各种膜拜大神OTZZZ T1珠 描述 萌蛋有n颗珠子,每一颗珠子都写有一个数字.萌蛋把它们用线串成了环.我们称一个数字串是有趣的,当且 ...
- CH Round #54 - Streaming #5 (NOIP模拟赛Day1)(被虐瞎)
http://ch.ezoj.tk/contest/CH%20Round%20%2354%20-%20Streaming%20%235%20%28NOIP%E6%A8%A1%E6%8B%9F%E8%B ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
- CH Round #49 - Streaming #4 (NOIP模拟赛Day2)
A.二叉树的的根 题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模 ...
- CH Round #55 - Streaming #6 (NOIP模拟赛day2)
A.九九归一 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2355%20-%20Streaming%20%236%20(NOIP模拟赛day2)/九九归一 题 ...
- CH Round #55 - Streaming #6 (NOIP模拟赛day2)解题报告
T1九九归一 描述 萌蛋在练习模n意义下的乘法时发现,总有一些数,在自乘若干次以后,会变成1.例如n=7,那么5×5 mod 7=4,4×5 mod 7=6,6×5 mod 7=2,2×5 mod 7 ...
随机推荐
- 前端工具之WebPack解密--使用
接上一篇的内容继续来说,背景篇的内容主要是介绍web前端工具的出现的原因和当前主要JavaScript模块化编程的几种规范!这篇内容主要介绍webpack的初级使用! 注意:目前webpack分为两个 ...
- oracle过滤分割字符串自定义函数
该函数实现过滤前后的指定的字符串,诸如过滤分隔符等.可用于过滤字符串中的逗号分割符.特别说明:substr()函数支持从字符串倒数开始读取,例如: dbms_output.put_line( subs ...
- oracle的安装与plsql的环境配置
1,首先得有oracle的安装包和plsql的安装包,安装包地址可见百度云 http://pan.baidu.com/s/1miTqhmg 2.解压下来进入0817账套,找到set.exe文件,双击安 ...
- a标签的背景图在ie8下显示问题
今天遇到个小问题,纠结了很久,分享下 a标签添加背景图,需要给a添加display:block样式 但是在ie8下还是不能显示背景图,开始以为是由于a标签为空造成的,试了下添加内容也没用,后来注意到一 ...
- 使用Spring简化JDBC操作数据库
Spring的开发初衷是为了减轻企业级开发的复杂度,其对数据库访问的支持亦如此,使用Spring访问数据库能带来以下好处: 1.1 简化代码 使用原生的JDBC访问数据库,一般总是要执行以下步 ...
- 如何利用C#编写网页投票器程序 如何使用代理来投票 代理IP来投票
一.前言看个图,了解下投票的过程.提交投票信息投票页 ――――――――>投票信息处理页反馈投票结果(请求页)<―――――――(响应页)一般情况下,填写投票信息,然后点提交按钮发送到响应 ...
- acl操作记录
官方文档内容: 1.CREATE_ACL Procedure创建ACL Note: This procedure is deprecated in Oracle Database 12c. While ...
- 受限玻尔兹曼机(RBM)
能量模型 RBM用到了能量模型. 简单的概括一下能量模型.假设一个孤立系统(总能量$E$一定,粒子个数$N$一定),温度恒定为1,每个粒子有$m$个可能的状态,每个状态对应一个能量$e_i$.那么,在 ...
- 【转】 UIview需要知道的一些事情:setNeedsDisplay、setNeedsLayout
原文:http://blog.sina.com.cn/s/blog_923fdd9b0101b2b4.html 1.在Mac OS中NSWindow的父类是NSResponder,而在iOS 中UIW ...
- Java线程(学习整理)--2---加入另一个线程join
1.join简介: 今天刚学的,这里我简单总结一下,join本身就是“加入”的意思,那么在线程中是什么意思呢?是在一个线程的run方法执行过程中,当特殊情况下需要执行一些其他的操作的时候,我们会用到j ...