题目链接:

http://files.cnblogs.com/files/TheRoadToTheGold/2017-6.11NOIP%E6%A8%A1%E6%8B%9F%E8%B5%9B.zip

期望得分:100+30+100=230

实际得分:0+30+100=130

T1 盘子序列

数据离散化,模拟栈

将盘子大小离散化 1——n

指针now开始指向1,依次递增,模拟初始盘堆A最上面的盘子

用a[i]存储收到的离散化之后的第i个盘子的大小,收到盘子的顺序也看做一个栈,记为栈C

st[]模拟盘堆B, top指针指向栈顶

然后分4种情况讨论

1、a[i]=now 初始盘堆A的最上面的盘子直接放到了栈C  now++

2、st[i]=now 盘堆B最上面的盘子放到栈C ,top--

3、盘堆A还有盘子,盘堆AB的顶端都不等于now,一直把A的盘子往B上放,直到等于now 或A没有盘子了

4、都不符合上面3种,有危险

最后判断st即B是否是升序排列,是则没有危险,否则有危险

#include<cstdio>
#include<algorithm>
#define N 100001
using namespace std;
int n,now,x;
int st[N],top,a[N];
bool ok;
struct node
{
int num,id;
}e[N];
bool cmp(node p,node q)
{
return p.num<q.num;
}
int main()
{
freopen("disk.in","r",stdin);
freopen("disk.out","w",stdout);
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=n;i++) scanf("%d",&e[i].num),e[i].id=i;
sort(e+,e+n+,cmp);
for(int i=;i<=n;i++) a[e[i].id]=i;
ok=; top=; now=;
for(int i=;i<=n;i++)
{
if(ok) continue;
if(a[i]==now) now++;
else if(top&&a[i]==st[top]) top--;
else if(now<n&&a[i]!=now)
{
while(a[i]!=now && now<n) st[++top]=now++;
now++;
}
else { printf("J\n"); ok=true;}
}
if(top>&&!ok)
{
for(int i=;i<top;i++)
if(st[i]>st[i+])
{
printf("J\n");
ok=true; break;
}
}
if(!ok) printf("Y\n");
}
}

0分原因:

第三种情况:

else if(now<n&&a[i]!=now)
{
  while(a[i]!=now && now<n) st[++top]=now++;
  now++;
}

while里漏了now<n,无限循环RE

T2 四轮车

离散化坐标

枚举两个点1、2固定一条边,根据正方形四边相等

那么

x3=x2+y2-y1; y3=y2+x1-x2;
x4=x1+y2-y1; y4=y1+x1-x2;

判断这两个点是否出现过

因为可能有重复点,所以去重后,设点出现了k次

没找到一个满足条件的,ans+=k1*k2*k3*k4

正方形的4条边都有可能是枚举的那条边,所以最后ans/4

代码中判断3、4是否存在的方法:

设离散化后的横坐标为nx,纵坐标为ny

[nx][ny] 出现过 (有序数对(nx,ny))

同时,hash_x[nx]=x,hash_y[ny]=y

hash[]:排序后的原数据

#include<cstdio>
#include<algorithm>
#define N 1001 using namespace std; int n,x[N],y[N],ans;
int sum[N][N];
bool v[N];
int eg[N][N];
int hashx[N+],hashy[N+],totx,toty,nx,ny;
int newx[N],newy[N]; int x1,x2,y1,y2,x3,x4,y3,y4,k1,k2,k3,k4;
void solve(int a,int b)
{
x1=x[a]; x2=x[b]; y1=y[a]; y2=y[b];
x3=x2+y2-y1; y3=y2+x1-x2;
x4=x1+y2-y1; y4=y1+x1-x2;
nx=lower_bound(hashx+,hashx+totx+,x3)-hashx;
ny=lower_bound(hashy+,hashy+toty+,y3)-hashy;
if(!(eg[nx][ny] && hashx[nx]==x3 && hashy[ny]==y3)) return ;
k3=sum[nx][ny];
nx=lower_bound(hashx+,hashx+totx+,x4)-hashx;
ny=lower_bound(hashy+,hashy+toty+,y4)-hashy;
if(!(eg[nx][ny] && hashx[nx]==x4 && hashy[ny]==y4)) return ;
k4=sum[nx][ny];
k1=sum[newx[a]][newy[a]]; k2=sum[newx[b]][newy[b]];
ans+=k1*k2*k3*k4;
//if(k1*k2*k3*k4) printf("%d,%d %d,%d %d,%d %d,%d\n",x1,y1,x2,y2,x3,y3,x4,y4);
// return k1*k2*k3*k4;
} int main()
{
/*freopen("car.in","r",stdin);
freopen("car.out","w",stdout);*/
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d",&x[i],&y[i]);
hashx[i]=x[i]; hashy[i]=y[i];
}
sort(hashx+,hashx+n+);
sort(hashy+,hashy+n+);
totx=unique(hashx+,hashx+n+)-(hashx+);
toty=unique(hashy+,hashy+n+)-(hashy+);
for(int i=;i<=n;i++)
{
nx=lower_bound(hashx+,hashx+totx+,x[i])-hashx;
ny=lower_bound(hashy+,hashy+toty+,y[i])-hashy;
newx[i]=nx; newy[i]=ny;
sum[nx][ny]++;
if(!eg[nx][ny]) eg[nx][ny]=i;
else v[i]=true;
}
for(int i=;i<=n;i++)
{
if(v[i]) continue;
for(int j=;j<=n;j++)
{
if(v[j] || i==j) continue;
solve(i,j);
//if(k) printf("%d %d %d\n",i,j,k);
}
}
printf("%d",ans/);
}

考场上打的30分暴力:

n^4枚举4个点,如果能构成正方形,ans++

构成正方形的4个点,固定住1个,剩余3个有3!种排法

所以同一个正方形会被重复计算4*3!=24次

最后ans/24

#include<cstdio>
#include<queue>
#define ref(x) for(x=1;x<=n;x++)
#define N 1001 using namespace std; int n,x[N],y[N],ans; inline int Length(int i,int j)
{
return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]) ;
} int main()
{
freopen("car.in","r",stdin);
freopen("car.out","w",stdout);
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
int a,b,c,d;
bool ok;
ref(a)
ref(b)
{
if(a==b) continue;
ref(c)
{
if(c==a||c==b) continue;
ref(d)
{
if(d==a||d==b||d==c) continue;
ok=false;
if((Length(a,b)==Length(b,c)) && (Length(b,c)==Length(c,d)) && (Length(c,d)==Length(d,a))) ok=true;
else if((Length(a,b)==Length(b,d)) && (Length(b,d)==Length(d,c)) && (Length(d,c)==Length(c,a))) ok=true;
else if((Length(a,c)==Length(c,b)) && (Length(c,b)==Length(b,d)) && (Length(b,d)==Length(d,a))) ok=true;
else if((Length(a,c)==Length(c,d)) && (Length(c,d)==Length(d,b)) && (Length(d,b)==Length(b,a))) ok=true;
else if((Length(a,d)==Length(d,b)) && (Length(d,b)==Length(b,c)) && (Length(b,c)==Length(c,a))) ok=true;
else if((Length(a,d)==Length(d,c)) && (Length(d,c)==Length(c,b)) && (Length(c,b)==Length(b,a))) ok=true;
if(ok) ans++;
}
}
}
printf("%d",ans/);
}

T3 点名

注:本题题目有误,应该是询问身高第k矮

法一:主席树查询区间k值

#include<cstdio>
#include<algorithm>
#define N 30001 using namespace std; int n,m,now,x,tot,ans;
long long high[N],tmp[N];
int hash[N];
int sum[N*]; int read1(int &x)
{
x=; char c=getchar();
while(c<''||c>'') c=getchar();
while(c>=''&&c<='') { x=x*+c-''; c=getchar(); }
}
long long read2(long long &x)
{
x=; char c=getchar();
while(c<''||c>'') c=getchar();
while(c>=''&&c<='') { x=x*+c-''; c=getchar(); }
}
void output(long long x)
{
if(x/) output(x/);
putchar(x%+'');
} struct President
{
void insert(int k,int l,int r,int pos)
{
sum[k]++;
if(l==r) return;
int mid=l+r>>;
if(pos<=mid) insert(k<<,l,mid,pos);
else insert(k<<|,mid+,r,pos);
}
int query(int k,int l,int r,int w)
{
if(l==r) return l;
int mid=l+r>>;
if(w<=sum[k<<]) return query(k<<,l,mid,w);
return query(k<<|,mid+,r,w-sum[k<<]);
}
}; President Tree; int main()
{
freopen("rollcall.in","r",stdin);
freopen("rollcall.out","w",stdout);
read1(n); read1(m);
int tot=n;
for(int i=;i<=n;i++) read2(high[i]),tmp[i]=high[i];
sort(high+,high+n+);
tot=unique(high+,high+n+)-(high+);
for(int i=;i<=n;i++) hash[i]=lower_bound(high+,high+tot+,tmp[i])-high; for(int i=;i<=m;i++)
{
scanf("%d",&x);
while(now!=x)
{
Tree.insert(,,tot,hash[now+]);
now++;
}
ans=Tree.query(,,tot,i);
output(high[ans]);
puts("");
}
}

法二:堆

http://www.cnblogs.com/TheRoadToTheGold/p/6995106.html

2017.6.11 NOIP模拟赛的更多相关文章

  1. 2017 10.25 NOIP模拟赛

    期望得分:100+40+100=240 实际得分:50+40+20=110 T1 start取了min没有用,w(゚Д゚)w    O(≧口≦)O T3 代码3个bug :数组开小了,一个细节没注意, ...

  2. 2017.5.27 NOIP模拟赛(hzwer2014-5-16 NOIP模拟赛)

    期望得分:100+100+60+30=290 实际得分:100+20+60+0=180 当务之急:提高一次正确率 Problem 1 双色球(ball.cpp/c/pas) [题目描述] 机房来了新一 ...

  3. 11/1 NOIP 模拟赛

    11.1 NOIP 模拟赛 期望得分:50:实际得分:50: 思路:暴力枚举 + 快速幂 #include <algorithm> #include <cstring> #in ...

  4. NOIP模拟赛-2018.11.7

    NOIP模拟赛 如果用命令行编译程序可以发现没加头文件之类的错误. 如果用命令行编译程序可以发现没加头文件之类的错误. 如果用命令行编译程序可以发现没加头文件之类的错误. 编译之前另存一份,听说如果敲 ...

  5. NOIP模拟赛-2018.11.6

    NOIP模拟赛 今天想着反正高一高二都要考试,那么干脆跟着高二考吧,因为高二的比赛更有技术含量(我自己带的键盘放在这里). 今天考了一套英文题?发现阅读理解还是有一些困难的. T1:有$n$个点,$m ...

  6. NOIP模拟赛-2018.11.5

    NOIP模拟赛 好像最近每天都会有模拟赛了.今天从高二逃考试跑到高一机房,然而高一也要考试,这回好像没有拒绝的理由了. 今天的模拟赛好像很有技术含量的感觉. T1:xgy断句. 好诡异的题目,首先给出 ...

  7. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  8. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  9. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

随机推荐

  1. linux下的常用技巧。

    xargs  linux下的多行合并~ [root@]# yum list installed|grep php|awk -F ' ' '{print $1}' php-channel-nrk.noa ...

  2. 20145214 《Java程序设计》第5周学习总结

    20145214 <Java程序设计>第5周学习总结 教材学习内容总结 try和catch Java中所有错误都会被包装为对象,可以尝试try执行程序并捕捉catch代表错误的对象后做一些 ...

  3. 常用算法Java实现之选择排序

    选择排序算法在每一步中选取最小值来重新排序,通过选择和交换来实现排序. 具体流程如下: 1.首先从原数组中选择最小的1个数据,将其置于第一个位置. 2.然后从剩下的数据中再选择其中最小的一个数据,并将 ...

  4. TCP系列27—窗口管理&流控—1、概述

    在前面的内容中我们依次介绍了TCP的连接建立和终止过程和TCP的各种重传方式.接着我们在这部分首先关注交互式应用TCP连接相关内容如延迟ACK.Nagle算法.Cork算法等,接着我们引入流控机制(f ...

  5. TCP系列08—连接管理—7、TCP 常见选项(option)

    一.TCP选项概述 在前面介绍TCP头的时候,我们说过tcp基本头下面可以带有tcp选项,其中有些选项只能在连接过程中随着SYN包发送,有些可以延后.下表汇总了一些tcp选项 其中我标记为红色的部分是 ...

  6. MongoDB、ElasticSearch、Redis、HBase这四种热门数据库的优缺点及应用场景

    MongoDB MongoDB是当今最火爆的NoSQL数据库.MongoDB最早在09年发布,算得上是早期大数据时代的数据库代表作了.随着MongoDB的火爆,研发MongoDB的团队还专门成立了Mo ...

  7. JAVA学习之泛型

    ArrayList<E>类定义和ArrayList<Integer>类引用中涉及的术语:1.整个ArrayList<E>称为泛型类型 2.ArrayList< ...

  8. javascript中检测一个变量的类型

    /** * 怎么检测一个变量的类型? * 在js中检测对象类型主要有三种:typeof, instanceof, constructor, 这几种都可以检测对象的类型. * 另外还可以适应jQuery ...

  9. C# 利用FTP自动下载xml文件后利用 FileSystemWatcher 监控目录下文件变化并自动更新数据库

    using FtpLib; using System; using System.Collections.Generic; using System.ComponentModel; using Sys ...

  10. Python虚拟环境virtualenv的使用

    virtualenv 是一个创建孤立的Python环境的工具.可以让你创建各自独立的.互不影响的Python开发环境. 使用pip安装即可 pip install virtualenv 查看是否安装成 ...