noip模拟赛#45
T1:n<=1e6,求最小的区间包含(1,m)的所有数。
=>双指针扫一遍即可
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
const int nmax=1e6+5;
const int maxn=2e3+5;
const int inf=0x7f7f7f7f;
int a[nmax],cnt[maxn];
int main(){
freopen("Exhibit.in","r",stdin);freopen("Exhibit.out","w",stdout);
int n=read(),m=read();rep(i,1,n) a[i]=read();
int r=1,sm=0,ans=inf,res;
rep(i,1,n){
while(sm<m&&r<=n) {
if(++cnt[a[r]]==1) ++sm;++r;
}--r;
//printf("(%d %d)\n",i,r);
if(sm==m){
if(ans>r-i+1) ans=r-i+1,res=i;
}
else break;
if(r==n) break;
if(!--cnt[a[i]]) --sm;++r;
}
printf("%d %d\n",res,res+ans-1);
fclose(stdin);fclose(stdout);
return 0;
}
/*
12 5
2 5 3 1 3 2 4 1 1 5 4 3
*/
T2:1000*1000的矩阵,求有多少个联通块。内存限制1M
=>懒得写暴力的了。。。正解似乎是并查集。我学的是ccz大爷的压位。就是压三位,其实多压几位也可以,char的范围是[-128,128],然后就可以省下了一大堆空间。。然后ccz大爷写的bfs很好看。。。学了%%%
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
char s[126][1001];
short q[4096][2];
#define push(x,y) ++qr,q[qr&4095][0]=x,q[qr&4095][1]=y,s[x>>3][y]-=(1<<(x&7))
void bfs(int x,int y){
int ql=1,qr=1;q[1][0]=x;q[1][1]=y;
while(ql<=qr){
x=q[ql&4095][0],y=q[ql&4095][1];++ql;
if(s[(x-1)>>3][y]&(1<<((x-1)&7))) push(x-1,y);
if(s[(x+1)>>3][y]&(1<<((x+1)&7))) push(x+1,y);
if(s[x>>3][y+1]&(1<<(x&7))) push(x,y+1);
if(s[x>>3][y-1]&(1<<(x&7))) push(x,y-1);
}
}
int main(){
freopen("Part.in","r",stdin);freopen("Part.out","w",stdout);
int n,u,v,d,tmp,temp;scanf("%d",&n);
rep(i,1,n) rep(j,1,n) {
scanf("%d",&u),s[i>>3][j]|=(1-u)<<(i&7);
//printf("(%d %d):%d\n",i,j,s[i>>3][j]);
}
int ans=0;
rep(i,1,n) rep(j,1,n) if(s[i>>3][j]&(1<<(i&7))) bfs(i,j),++ans;
printf("%d\n",ans);
fclose(stdin);fclose(stdout);
return 0;
}
/*
5
1 0 0 1 0
0 0 0 0 1
0 1 0 1 0
1 0 1 0 1
0 0 0 0 0
*/
T3:给一个数n,将n分解成若干个数的和。求最大的最小公倍数。答案<=1e25;
=>不会写。。。正解是利用一个性质就是2*3>2+3 f[2*3]<f[2+3],所以每一个数必定只含有一个质因子。那么dp一下就可以了,然后再高精度。。
=>然后高精度很少写operator<的时候一直弄错。。。而且100以内的质数表自己手写写错了T_T。。。maya
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
using namespace std;
#define rep(i,s,t) for(ll i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
#define ll long long
const int a[]={0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
struct node{
int s[30],n;
node(int _n=0){
n=_n;clr(s,0);
}
node operator*(int k){
node res(n);
rep(i,1,n) res.s[i]=s[i]*k;
rep(i,1,res.n) if(res.s[i]>=10) res.s[i+1]+=res.s[i]/10,res.s[i]%=10;
if(res.s[n+1]) res.n++;
for(;res.s[res.n];++res.n) if(res.s[res.n]>=10) {
res.s[res.n+1]+=res.s[res.n]/10;
res.s[res.n]%=10;
}--res.n;
return res;
}
node operator=(int x){
for(n=0;x;x/=10) s[++n]=x%10;
return *this;
}
node operator=(const node&o){
n=o.n;
rep(i,1,n) s[i]=o.s[i];
return *this;
}
bool operator<(const node&o){
if(n<o.n) return 1;
if(n>o.n) return 0;
dwn(i,n,1){
if(s[i]<o.s[i]) return 1;
if(s[i]>o.s[i]) return 0;
}
return 0;
}
void write(){
dwn(i,n,1) printf("%d",s[i]);printf("\n");
}
};
node f[30][1200];
int main(){
freopen("Lcm.in","r",stdin);freopen("Lcm.out","w",stdout);
int n;scanf("%d",&n);
rep(i,0,n) f[0][i]=1;
rep(i,1,25){
rep(j,a[i],n){
f[i][j]=f[i-1][j];
for(int k=a[i];k<=j;k=k*a[i]) if(f[i][j]<f[i-1][j-k]*k){
f[i][j]=f[i-1][j-k]*k;
}
}
}
node ans=0;
rep(i,1,25) if(ans<f[i][n]) ans=f[i][n];
ans.write();
fclose(stdin);fclose(stdout);
return 0;
}
/*
30
2 2 3 5 7 11
*/
noip模拟赛#45的更多相关文章
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- 队爷的讲学计划 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 #58 - OrzCC杯noip模拟赛day2
A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...
- CH Round #52 - Thinking Bear #1 (NOIP模拟赛)
A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...
随机推荐
- Socket()与WSASocket()的区别
socket() 创建一个通讯端点并返回一个套接口.但是在socket库中例程在应用于阻塞套接口时会阻塞. WSASocket()的发送操作和接收操作都可以被重叠使用.接收函数可以被多次调 ...
- UniqueIdentifier 数据类型
UniqueIdentifier 数据类型用于存储GUID的值,占用16Byte. SQL Server将UniqueIdentifier存储为16字节的二进制数值,Binary(16),按照特定的格 ...
- EntityFramework数据库配置(code frist)
什么也不说先贴代码 <?xml version="1.0" encoding="utf-8"?> <configuration> < ...
- 聊聊心跳机制及netty心跳实现
我们在使用netty的时候会使用一个参数,ChannelOption.SO_KEEPALIVE为true, 设置好了之后再Linux系统才会对keepalive生效,但是linux里边需要配置几个参数 ...
- PHP之递归函数
https://www.cnsecer.com/4146.html http://www.jb51.net/article/71424.htm //一列数字的规则如下:1,1,2,3,5,8,13,2 ...
- 30岁程序员的焦虑 Anxiety of 30-year-old Programmers
还有四个月,我就30周岁了.圈里都在传30岁程序员的焦虑,我也焦虑.身边的朋友,除了已经上岸的一部分,说不焦虑的,几乎找不到. 我们不妨认真地来聊一下这个话题:30岁,程序员,焦虑. 首先,什么是焦虑 ...
- 正整数构成的线性表存放在单链表中,编写算法将表中的所有的奇数删除。(C语言)
/* 正整数构成的线性表存放在单链表中,编写算法将表中的所有的奇数删除 */ #include <stdio.h> #include <stdlib.h> typedef st ...
- C# 数组之int[]
一.数组分类 数组可以简单分为3类: 1维数组 2维数组 交错数组 二.数组初始化 1.一维数组 int [] A = { 1,2,3,4 } 直接赋值 或者 int [] A = new int [ ...
- Codeforces 161C(分治、性质)
要点 因为当前最大字符只有一个且两边是回文的,所以如果答案包含最大字符则一定是重合部分. 若不包含,则用此字符将两个区间分别断为两部分,则共有四种组合,答案一定为其中之一. #include < ...
- 1550: Simple String 最大流解法
http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1550 很久以前做的一题,当时队友用最大流做,现在我也是 这个转化为二分图多重匹配,就是一样的意 ...