题目链接:

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. [C++] String Basic

    Namespace Declarations A using declaration let us use a name from a namespace without qualify the na ...

  2. C中文件操作的文本模式和二进制模式,到底有啥区别?

    在C中,使用fopen打开文件有两种模式:一种是文本模式,一种是二进制模式.那这两种模式之间有什么区别,是不是使用文本模式打开的文件就只能使用文本函数比如fprintf来操作,而使用二进制打开的文件就 ...

  3. 软件工程 作业part2 采访

    Part 2 采访本课程往届同学(含外校和毕业生). 现代软件工程这门课已经上了好几年了,以前有很多学生做过团队项目(说不定包括本校的学生),请你们找一个以前的团队采访一下. 我采访的是2016级于淼 ...

  4. 你代码写得这么丑,一定是因为你长得不好看----panboo第一篇博客

    一.个人介绍 我叫潘博,软嵌162,学号1613072055. 以“panboo”名称混迹于各大开源IT论坛与博客. 除了编程,我的最大爱好是篮球与健身,热衷于各种IT技术与运动. 我做过的软件项目有 ...

  5. block知识总结

    一.block在内存中存在的形式 1.当把block句法写在函数或者方法外面时,系统会在静态数据区分配一块内存区域给block对象.这片区域在程序执行期会一直存在. 2.当block句法写在函数或者方 ...

  6. android入门 — ListView点击事件

    listView中提供了两种点击事件的处理方法,分别是OnItemClick和OnItemLongClick. OnItemClick提供的是点击操作的处理,OnItemLongClick提供的是长按 ...

  7. 团队作业7——第二次项目冲刺(Beta版本)-第三篇

    1.工作分工: 团队成员 分工 郭达22120 项目整合,后台代码 刘德培44060 前台界面优化 石浩洋22061 前台界面优化 曾繁钦22056 前台界面优化.测试 孙斌22030 后台代码 2. ...

  8. <Effective C++>读书摘要--Inheritance and Object-Oriented Design<二>

    <Item 36> Never redefine an inherited non-virtual function 1.如下代码通过不同指针调用同一个对象的同一个函数会产生不同的行为Th ...

  9. mysql表、函数等被锁住无响应的问题

    场景: 在对表或函数等进行操作的时候,如果出现无法响应的情况(排除外网的网络问题),此时极有可能被某一个线程锁定了(这是函数的情况,表的话可能是被某一个用户锁定了),锁定的原因一般都是死循环出不来,而 ...

  10. javascript中的this作用域详解

    javascript中的this作用域详解 Javascript中this的指向一直是困扰我很久的问题,在使用中出错的机率也非常大.在面向对象语言中,它代表了当前对象的一个引用,而在js中却经常让我觉 ...