usaco /the second wave
bzoj4582:简单递推题。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,s,t) for(int i=s;i<=t;i++)
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=50005;
int a[nmax],rmax[nmax],res[nmax];
int main(){
int n=read(),k=read();
REP(i,1,n) a[i]=read();
sort(a+1,a+n+1);
REP(i,1,n){
int tmp=i;
while(a[tmp]-a[i]<=k&&tmp<=n) tmp++;
rmax[i]=tmp-i;
}
for(int i=n;i;i--) res[i]=max(res[i+1],rmax[i]);
int ans=-1;
REP(i,1,n) ans=max(ans,rmax[i]+res[i+rmax[i]]);
printf("%d\n",ans);
return 0;
}
bzoj4525:二分答案+贪心判断。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,s,t) for(int i=s;i<=t;i++)
#define clr(x,c) memset(x,c,sizeof(x))
const int nmax=50005;
int a[nmax],n,m;
int read(){
int x=0;char c=getchar();bool f=true;
while(!isdigit(c)){
if(c=='-') f=false;c=getchar();
}
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return f?x:-x;
}
bool check(int x){
int ans=0;
REP(i,1,n){
int temp=a[i];
while(a[i]-temp<=x*2&&i<=n) i++;
i--;
ans++;
}
if(ans<=m) return true;
return false;
}
int main(){
n=read(),m=read();
REP(i,1,n) a[i]=read();
sort(a+1,a+n+1);
int l=0,r=1000000000,mid,ans;
while(l<=r){
mid=(l+r)>>1;
if(check(mid)) ans=mid,r=mid-1;
else l=mid+1;
}
printf("%d\n",ans);
return 0;
}
bzoj4511:模拟。。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int x;char c;
int read(){
x=0;c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
int a[7],n,tmp,sum=0,ans=0;
int main(){
memset(a,-1,sizeof(a));
a[0]=0;
n=read();
for(int i=1;i<=n;i++){
tmp=read();
sum+=tmp,sum%=7;
if(a[sum]!=-1) ans=max(ans,i-a[sum]);
else a[sum]=i;
}
printf("%d\n",ans);
return 0;
}
bzoj4397:模拟。。。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,s,t) for(int i=1;i<=t;i++)
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=100005;
int a[nmax],b[nmax],c[nmax];
int main(){
int n=read(),m=read();
REP(i,1,n) {
a[i]=a[i-1],b[i]=b[i-1],c[i]=c[i-1];
int tmp=read();
if(tmp==1) a[i]++;
else if(tmp==2) b[i]++;
else c[i]++;
}
REP(i,1,m){
int s=read(),t=read();
printf("%d %d %d\n",a[t]-a[s-1],b[t]-b[s-1],c[t]-c[s-1]);
}
return 0;
}
bzoj4396:简单递推题。。。
#include<cstdio>
#include<iostream>
using namespace std;
const int nmax=100005;
bool vis[nmax];
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;
}
int main(){
int n=read();
for(int i=1;i<=n;i++) vis[read()]=true;
n+=n;
int l=1,ans=0;
for(int i=1;i<=n;i++) if(!vis[i]){
while(!vis[l]) l++;
if(l<i) l++,ans++;
}
printf("%d\n",ans);
return 0;
}
usaco /the second wave的更多相关文章
- usaco /the first wave
bzoj1572:贪心.先按时间顺序排序,然后用优先队列,如果时间不矛盾直接插入,否则判断队列中w最小的元素是否替换掉.(没用llWA了一次 #include<cstdio> #inclu ...
- 3408: [Usaco2009 Oct]Heat Wave 热浪
3408: [Usaco2009 Oct]Heat Wave 热浪 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 67 Solved: 55[Subm ...
- RIFF和WAVE音频文件格式
RIFF file format RIFF全称为资源互换文件格式(Resources Interchange File Format),是Windows下大部分多媒体文件遵循的一种文件结构.RIFF文 ...
- USACO . Your Ride Is Here
Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...
- IEEE 802.11p (WAVE,Wireless Access in the Vehicular Environment)
IEEE 802.11p(又称WAVE,Wireless Access in the Vehicular Environment)是一个由IEEE 802.11标准扩充的通讯协定.这个通讯协定主要用在 ...
- 【USACO 3.1】Stamps (完全背包)
题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...
- USACO翻译:USACO 2013 NOV Silver三题
USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...
- USACO翻译:USACO 2013 DEC Silver三题
USACO 2013 DEC SILVER 一.题目概览 中文题目名称 挤奶调度 农场航线 贝西洗牌 英文题目名称 msched vacation shuffle 可执行文件名 msched vaca ...
- USACO翻译:USACO 2014 DEC Silver三题
USACO 2014 DEC SILVER 一.题目概览 中文题目名称 回程 马拉松 奶牛慢跑 英文题目名称 piggyback marathon cowjog 可执行文件名 piggyback ma ...
随机推荐
- PySide 简易教程<一>-------Hello PySide
PySide 是一个python绑定的跨平台GUI Qt库.目前,支持Python的Qt库有两个PyQt和PySide.PySide是一个免费的软件,与PyQt不同之处在于使用了LGPL,允许PySi ...
- 零基础学Python 3之环境准备
一. 配置python 3 环境 1. Python 3 下载 64位 https://www.python.org/ftp/python/3.4.2/python-3.4.2.amd64.msi 3 ...
- SVN备份教程(一)
最近一段时间在项目中用到了SVN备份的相关内容,这里给大家做一个简单的教程,重点在于SVN备份环境的搭建过程中,大家学到的解决问题的思维方式. 1.分类 SVN备份主要分为两种:一种是远程备份,另一种 ...
- hive-site.xml 参数设置
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="confi ...
- TCP报头
源端口和目的端口: 各占16位 ,服务相对应的源端口和目的端口. 序列号: 占32位,它的范围在[0~2^32-1],序号随着通信的进行不断的递增,当达到最大值的时候重新回到0在开始递增.TCP是面向 ...
- java和php实现RSA加密互通-b
java和PHP RSA加密实现互通 1:通过openssl 生成公钥和密钥文件(linux) (1) 生产私钥文件命令 openssl genrsa -out rsa_private_key.pe ...
- android/IOS各平台分享链接/跳转链接配置说明(备用)
Android: [Java] 纯文本查看 复制代码 ? 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 微信/朋友圈 //设置 ...
- [转载]jQuery.lazyload详解 - 图片延时加载
jQuery实现图片延迟加载,不知道是否可以节省带宽呢?有人知道吗? 这究竟只是一个视觉特效还是真的能延迟加载减少服务器的请求呢? <script type="text/javascr ...
- EhCache 分布式缓存/缓存集群(转)
开发环境: System:Windows JavaEE Server:tomcat5.0.2.8.tomcat6 JavaSDK: jdk6+ IDE:eclipse.MyEclipse 6.6 开发 ...
- hibernate hql 大全
Hibernate配备了一种非常强大的查询语言,这种语言看上去很像SQL.但是不要被语法结构 上的相似所迷惑,HQL是非常有意识的被设计为完全面向对象的查询,它可以理解如继承.多态 和关联之类的概念. ...