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 ...
随机推荐
- IT兄弟连 Java语法教程 Java开发环境 配置Java环境变量
在安装完JDK后,我们需要配置系统的环境变量,否则在控制台中使用JDK为我们提供的工具时将出现如图12所示的错误信息. 图12 未配置环境变量时执行java命令提示的错误信息 当出现这样的提示信息时 ...
- Linux常用命令汇总(未完,待补充)
由于工作中经常要和Linux服务器打交道,故整理了一些常用的Linux命令,方便新入职的同学或实习生参考学习. 1. 查看Linux内核版本 #uname -a 2. ctrl+insert:复制选中 ...
- java五行代码导出Excel
目录 先看代码 再看效果 EasyExcel 附: Java按模板导出Excel---基于Aspose实现 Java无模板导出Excel,Apache-POI插件实现 已经写过两种Excel导出插件了 ...
- 13.Python略有小成(装饰器,递归函数)
Python(装饰器,递归函数) 一.开放封闭原则 软件面世时,不可能把所有的功能都设计好,再未来的一两年功能会陆续上线,定期更新迭代,软件之前所用的源代码,函数里面的代码以及函数的调用方式一般不 ...
- 使用Etherscan API通过区块号获取块及叔块奖励
本文原文链接 点击这里获取Etherscan API 中文文档(完整版) 完整内容排版更好,推荐读者前往阅读. 区块(Blocks) 区块相关的 API,接口的参数说明请参考Etherscan API ...
- oracle view and MATERIALIZED VIEW
View http://blog.csdn.net/tianlesoftware/article/details/5530618 MATERIALIZED VIEW http://blog.csdn. ...
- String常用方法简介
1. 创建String对象的常用方法 (1) String s1 = "mpptest" (2) String s2 = new String(); (3) String s3 ...
- Codeforces 185B(数学结论)
要点 有不等式\(x^ay^bz^c=a^ab^bc^c(\frac{x}{a})^a(\frac{y}{b})^b(\frac{z}{c})^c<=a^ab^bc^c(\frac{x+y+z} ...
- maven settings.xml linux
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Soft ...
- Netty(7)-传对象
改造timer,即客户端与服务端建立连接后,服务端主动向客户端发送当前时间. server: ch.pipeline().addLast(new TimeEncoder()); ch.pipeline ...