博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NOIP模拟赛
阅读量:4678 次
发布时间:2019-06-09

本文共 5610 字,大约阅读时间需要 18 分钟。

题目背景

此题约为NOIP提高组Day1T1难度。

题目描述

B君站在一个n\times nn×n的棋盘上。最开始,B君站在(1,1)这个点,他要走到(n,n)这个点。

B君每秒可以向上下左右的某个方向移动一格,但是很不妙,C君打算阻止B君的计划。

每秒结束的时刻,C君会在(x,y)上摆一个路障。B君不能走在路障上。

B君拿到了C君准备在哪些点放置路障。所以现在你需要判断,B君能否成功走到(n,n)

保证不会走到某处,然后被一个路障砸死。

输入输出格式

输入格式:

 

首先是一个正整数T,表示数据组数。

对于每一组数据:

第一行,一个正整数n

接下来2n-2行,每行两个正整数xy,意义是在那一秒结束后,(x,y)将被摆上路障。

 

输出格式:

 

对于每一组数据,输出YesNo,回答B君能否走到(n,n)

 

输入输出样例

输入样例#1: 
221 12 253 33 23 11 21 31 41 52 2
输出样例#1: 
YesYes

说明

样例解释:

以下0表示能走,x表示不能走,B表示B君现在的位置。从左往右表示时间。

Case 1:0 0    0 0 0 B (已经走到了) B 0 x B x 0
Case 2:0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x 0 0 0 0 x 0 0 0 0 x 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x 0 0 0 0 x 0 0 B 0 0 0 0 0 B 0 0 0 0 0 B 0 0 0 0 x B 0 ......(B君可以走到终点)

数据规模:

防止骗分,数据保证全部手造。

对于20%的数据,有n<=3

对于60%的数据,有n<=500

对于100%的数据,有n<=1000

对于100%的数据,有T<=10

#include
#include
#include
#include
#include
using namespace std;int T,n,tot;int vis[1001][1001];int x[2001],y[2001];int dx[4]={
0,0,1,-1};int dy[4]={
1,-1,0,0};int bfs(int sx,int sy){ vis[sx][sy]=1;tot=0; queue
que1,que2; que1.push(sx);que2.push(sy); while(!que1.empty()){ int nowx=que1.front(); int nowy=que2.front(); que1.pop();que2.pop(); for(int i=0;i<4;i++){ int cx=nowx+dx[i]; int cy=nowy+dy[i]; if(cx>=1&&cx<=n&&cy>=1&&cy<=n&&!vis[cx][cy]){ vis[cx][cy]=1; que1.push(cx);que2.push(cy); if(cx==n&&cy==n) return 1; } } vis[x[++tot]][y[tot]]=1; } return 0;}int main(){ scanf("%d",&T); while(T--){ scanf("%d",&n); for(int i=1;i<=2*n-2;i++) scanf("%d%d",&x[i],&y[i]); if(bfs(1,1)) printf("Yes\n"); else printf("No\n"); memset(vis,0,sizeof(vis)); }}

题目背景

此题约为NOIP提高组Day2T1难度。

题目描述

n\*n的格子上有m个地毯。

给出这些地毯的信息,问每个点被多少个地毯覆盖。

输入输出格式

输入格式:

 

第一行,两个正整数n、m。意义如题所述。

接下来m行,每行两个坐标(x1,y1)(x2,y2),代表一块地毯,左上角是(x1,y1),右下角是(x2,y2)

 

输出格式:

 

输出n行,每行n个正整数。

i行第j列的正整数表示(i,j)这个格子被多少个地毯覆盖。

 

输入输出样例

输入样例#1: 
5 32 2 3 33 3 5 51 2 1 4
输出样例#1: 
0 1 1 1 00 1 1 0 00 1 2 1 10 0 1 1 10 0 1 1 1

说明

样例解释

0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 -> 0 1 2 1 1 -> 0 1 2 1 1 0 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 1 1 1

数据范围

对于20%的数据,有n<=50m<=100

对于100%的数据,有n<=1000m<=1000

#include
#include
#include
#include
using namespace std;int n,m;int map[1001][1001];int main(){ scanf("%d%d",&n,&m); for(int k=1;k<=m;k++){ int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); for(int i=x1;i<=x2;i++) for(int j=y1;j<=y2;j++) map[i][j]++; } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++) printf("%d ",map[i][j]); printf("\n"); }}

题目背景

此题约为NOIP提高组Day2T2难度。

题目描述

众所周知,模数的hash会产生冲突。例如,如果模的数p=7,那么411便冲突了。

B君对hash冲突很感兴趣。他会给出一个正整数序列value[]

自然,B君会把这些数据存进hash池。第value[k]会被存进(k%p)这个池。这样就能造成很多冲突。

B君会给定许多个px,询问在模p时,x这个池内数的总和

另外,B君会随时更改value[k]。每次更改立即生效。

保证1<=p<n1<=p<n.

输入输出格式

输入格式:

 

第一行,两个正整数n,m,其中n代表序列长度,m代表B君的操作次数。

第一行,n个正整数,代表初始序列。

接下来m行,首先是一个字符cmd,然后是两个整数x,y

  • cmd='A',则询问在模x时,y池内数的总和。

  • cmd='C',则将value[x]修改为y

 

输出格式:

 

对于每个询问输出一个正整数,进行回答。

 

输入输出样例

输入样例#1: 
10 51 2 3 4 5 6 7 8 9 10A 2 1C 1 20A 3 1C 5 1A 5 0
输出样例#1: 
254111

说明

样例解释

A 2 1的答案是1+3+5+7+9=25.

A 3 1的答案是20+4+7+10=41.

A 5 0的答案是1+10=11.

数据规模

对于10%的数据,有n<=1000,m<=1000.

对于60%的数据,有n<=100000.m<=100000.

对于100%的数据,有n<=150000,m<=150000.

保证所有数据合法,且1<=value[i]<=1000.

#include
#include
#include
#include
using namespace std;int n,m,ans;int val[150010];int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d",&val[i]); for(int i=1;i<=m;i++){ char s[10];int x,y; cin>>s>>x>>y; if(s[0]=='A'){ for(int j=y;j<=n;j+=x) ans+=val[j]; printf("%d\n",ans);ans=0; } else if(s[0]=='C') val[x]=y; }}
91分的暴力

 

#include
#include
#include
#include
#include
using namespace std;int n,m;int val[150010];int ans[1010][1010];int gets(int x,int y){ if(x<=sqrt(n)) return ans[x][y]; else { int bns=0; for(int q=y;q<=n;q+=x) bns+=val[q]; return bns; }}int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d",&val[i]); /*for(int i=1;i<=m;i++){ char s[10];int x,y; cin>>s>>x>>y; if(s[0]=='A'){ for(int j=y;j<=n;j+=x) ans+=val[j]; printf("%d\n",ans);ans=0; } else if(s[0]=='C') val[x]=y; }*/ for(int p=1;p<=sqrt(n);p++) for(int i=1;i<=n;i++) ans[p][i%p]+=val[i]; for(int i=1;i<=m;i++){ char s[10];int x,y; cin>>s>>x>>y; if(s[0]=='A') printf("%d\n",gets(x,y)); else if(s[0]=='C'){ for(int p=1;p<=sqrt(n);p++) ans[p][x%p]=ans[p][x%p]-val[x]+y; val[x]=y; } }}

 

转载于:https://www.cnblogs.com/cangT-Tlan/p/9655739.html

你可能感兴趣的文章
git + git flow 的简单介绍
查看>>
如果我们想要交换两个数字,就可以使用位运算
查看>>
求给出第 K个 N位二进制数,该二进制数不得有相邻的“1”
查看>>
P1059 明明的随机数【去重排序】
查看>>
HDU 1060 Leftmost Digit【log10/求N^N的最高位数字是多少】
查看>>
tomcat配置文件web.xml与server.xml解析--重要
查看>>
【C语言】《C Primer Plus》递归:以二进制形式输出整数
查看>>
使用框架的——好处
查看>>
如此大量的代码,但每个类里面的代码却不显得特别多,原因。。。。。。。。。。。。...
查看>>
C#特征备忘
查看>>
Java 面向对象 之 final 关键字
查看>>
Contact Form 7邮件发送失败的解决办法
查看>>
P1800 software_NOI导刊2010提高(06)
查看>>
Python学习日记(1)使用if __name__ == "main"
查看>>
二进制的最大公约数
查看>>
Mybatis学习笔记(一) 之框架原理
查看>>
ABSTRACT的方法是否可同时是STATIC,是否可同时是NATIVE,是否可同时是SYNCHRONIZED?
查看>>
【SPL标准库专题(10)】SPL Exceptions
查看>>
《Python从入门基础到实践》
查看>>
【读入优化】
查看>>