bzoj1572:贪心。先按时间顺序排序,然后用优先队列,如果时间不矛盾直接插入,否则判断队列中w最小的元素是否替换掉。(没用llWA了一次

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#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 ll long long
#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=100005;
struct Node{
int num,w;
bool operator<(const Node&rhs)const{
return num<rhs.num;}
};
Node Nodes[nmax];
struct node{
int num,w;
bool operator<(const node&rhs)const{
return w>rhs.w;}
};
node nodes[nmax];
priority_queue<node>q;
int main(){
int n=read();
REP(i,1,n) Nodes[i].num=read(),Nodes[i].w=read();
sort(Nodes+1,Nodes+n+1);
REP(i,1,n) nodes[i].num=Nodes[i].num,nodes[i].w=Nodes[i].w;
REP(i,1,n){
node o=nodes[i];
if(o.num>q.size()) {
q.push(o);continue;
}
node tp=q.top();
if(tp.w<o.w) q.pop(),q.push(o);
}
ll ans=0;
while(!q.empty()) ans+=q.top().w,q.pop();
printf("%lld\n",ans);
return 0;
}

bzoj1574:贪心,将不能到达的点与相连的点集删除,然后dfs。(两个数组名相同RE了一次

#include<cstdio>
#include<cstring>
#include<iostream>
#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))
#define qwq(x) for(edge *o=head[x];o;o=o->next)
#define op() clr(head,0);pt=edges;
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=30005;
const int maxn=200005;
struct edge{
int to;edge *next;
};
edge edges[maxn],*pt,*head[nmax];
bool vis[nmax],V[nmax];
void adde(int u,int v){
pt->to=v;pt->next=head[u];head[u]=pt++;
pt->to=u;pt->next=head[v];head[v]=pt++;
}
void dfs(int x){
V[x]=true;
qwq(x) if(vis[o->to]&&!V[o->to]) dfs(o->to);
}
int main(){
op();clr(vis,true);clr(V,false);
int N=read(),M=read(),P=read(),u,v;
REP(i,1,M) u=read(),v=read(),adde(u,v);
REP(i,1,P) {
u=read();vis[u]=false;
qwq(u) vis[o->to]=false;
}
dfs(1);
int ans=N;
REP(i,1,N) if(V[i]) ans--;
printf("%d\n",ans);
return 0;
}

bzoj1576:由于最短路唯一。所以有最短路径树。未在树中的边u,v对于lca(u,v)以下的点,有dist[x]=dist[u]+dist[v]+val[u,v]-dist[x](与dist[x]无关。可以将dist[u]+dist[v]+val[u,v]排序,依次更新。由于先更新的必定更优,于是可以用并查集压缩路径。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
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))
#define qwq(x) for(edge *o=head[x];o;o=o->next)
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;
const int maxn=400005;
const int inf=0x7f7f7f7f; struct edge{
int to,dist;edge *next;
};
edge edges[maxn],*pt,*head[nmax];
int d[nmax],dep[nmax],fa[nmax],ans[nmax];
void adde(int u,int v,int d){
pt->to=v;pt->dist=d;pt->next=head[u];head[u]=pt++;
pt->to=u;pt->dist=d;pt->next=head[v];head[v]=pt++;
} struct node{
int x,d;
node(int x,int d):x(x),d(d){}
bool operator<(const node&rhs) const{
return d>rhs.d;}
};
priority_queue<node>q;
void dijkstra(){
clr(d,0x7f);d[1]=0;dep[1]=0;
q.push(node(1,0));
while(!q.empty()){
node tmp=q.top();q.pop();
if(d[tmp.x]!=tmp.d) continue;
qwq(tmp.x) if(d[o->to]>d[tmp.x]+o->dist){
d[o->to]=d[tmp.x]+o->dist;
dep[o->to]=dep[tmp.x]+1;fa[o->to]=tmp.x;
q.push(node(o->to,d[o->to]));
}
}
} struct zc{
int from,to,dist;
bool operator<(const zc&rhs) const{
return dist<rhs.dist;}
};
zc zcs[maxn]; void getdep(int x){ }
int update(int u,int v,int val){
if(u==v) return u;
if(dep[u]<dep[v]) swap(u,v);
if(ans[u]==-1) ans[u]=val-d[u];
return fa[u]=update(fa[u],v,val);
} int main(){
clr(head,0);pt=edges;
int N=read(),M=read(),u,v,dd;
REP(i,1,M) {
u=read(),v=read(),dd=read(),adde(u,v,dd);
zc &oo=zcs[i];oo.from=u,oo.to=v,oo.dist=dd;
}
dijkstra();
REP(i,1,N) printf("%d:%d\n",i,dep[i]); int cnt=0;
REP(i,1,M) {
zc &oo=zcs[i];
if(d[oo.from]==d[oo.to]+oo.dist||d[oo.to]==d[oo.from]+oo.dist) continue;
zc &ee=zcs[++cnt];
ee.from=oo.from,ee.to=oo.to,ee.dist=d[oo.from]+d[oo.to]+oo.dist;
}
sort(zcs+1,zcs+cnt+1); clr(ans,-1);
REP(i,1,cnt) update(zcs[i].from,zcs[i].to,zcs[i].dist);
REP(i,2,N) printf("%d\n",ans[i]);
return 0;
}

bzoj1585:建图后最小割就可以了。(由于没有处理第一个点的情况WA了一次

#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))
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=10005;
const int maxn=200005;
const int inf=0x7f7f7f7f;
struct edge{
int to,cap;edge *next,*rev;
};
edge edges[maxn],*pt,*head[nmax],*cur[nmax],*p[nmax];
void add(int u,int v,int d){
pt->to=v;pt->cap=d;pt->next=head[u];head[u]=pt++;
}
void adde(int u,int v,int d){
add(u,v,d);add(v,u,0);head[u]->rev=head[v];head[v]->rev=head[u];
} int cnt[nmax],h[nmax];
int maxflow(int s,int t,int n){
clr(cnt,0);cnt[0]=n;clr(h,0);
int flow=0,a=inf,x=s;edge *e;
while(h[s]<n){
for(e=cur[x];e;e=e->next) if(e->cap>0&&h[x]==h[e->to]+1) break;
if(e){
a=min(a,e->cap);cur[x]=p[e->to]=e;x=e->to;
if(x==t){
while(x!=s) p[x]->cap-=a,p[x]->rev->cap+=a,x=p[x]->rev->to;
flow+=a,a=inf;
}
}else{
if(!--cnt[h[x]]) break;
h[x]=n;
for(e=head[x];e;e=e->next) if(e->cap>0&&h[x]>h[e->to]+1) h[x]=h[e->to]+1,cur[x]=e;
cnt[h[x]]++;
if(x!=s) x=p[x]->rev->to;
}
}
return flow;
} bool vis[nmax];
int main(){
clr(head,0);pt=edges;clr(vis,false);
int N=read(),M=read(),P=read(),s=0,t=N+N+1;
adde(s,1,inf);
REP(i,1,M){
int u=read(),v=read();
adde(u+u,v+v-1,inf);adde(v+v,u+u-1,inf);
}
REP(i,1,P){
int u=read();vis[u]=true;
}
adde(1,2,inf);
REP(i,2,N){
if(vis[i]) adde(i+i-1,i+i,inf),adde(i+i,t,inf);
else adde(i+i-1,i+i,1);
}
printf("%d\n",maxflow(s,t,t+1));
return 0;
}

bzoj1589:tarjan缩点后乱搞即可。(读入优化x=x*1+c-'0',由于自己出的都是小数据所以没有发现WA了一次。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stack>
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))
#define qwq(x) for(edge *o=head[x];o;o=o->next)
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=200005;
const int maxn=400005;
const int inf=0x7f7f7f7f;
struct edge{
int to;edge *next;
};
edge edges[maxn],*pt,*head[nmax];
void add(int u,int v){
pt->to=v;pt->next=head[u];head[u]=pt++;
} int sccno[nmax],scc[nmax],pre[nmax],scc_cnt,dfs_clock=0;
stack<int>s;
int dfs(int x){
int lowu=pre[x]=++dfs_clock;
s.push(x);
qwq(x){
int to=o->to;
if(!pre[to]) lowu=min(lowu,dfs(to));
else if(!sccno[to]) lowu=min(lowu,pre[to]);
}
if(lowu==pre[x]){
scc_cnt++;scc[scc_cnt]=0;
while(1){
int tmp=s.top();s.pop();
sccno[tmp]=scc_cnt;scc[scc_cnt]++;
if(tmp==x) break;
}
}
return lowu;
} int sum[nmax];
int getsum(int x){
if(sum[x]) return sum[x];
int ans=scc[x];
qwq(x) ans+=getsum(o->to);
return ans;
} int main(){
clr(head,0);pt=edges;
int N=read(),u;
REP(i,1,N) u=read(),add(i,u); scc_cnt=N;
REP(i,1,N) if(!pre[i]) dfs(i);
REP(i,1,N) qwq(i) if(sccno[i]!=sccno[o->to]) add(sccno[i],sccno[o->to]);
REP(i,N+1,scc_cnt) sum[i]=getsum(i);
REP(i,1,N) printf("%d\n",sum[sccno[i]]);
return 0;
}

summary:

1.各种神奇的错误方式。。。

2.自己出的数据也不要太小。。。但也不要自己被自己出的数据绕晕了。。。

usaco /the first wave的更多相关文章

  1. usaco /the second wave

    bzoj4582:简单递推题. #include<cstdio> #include<cstring> #include<iostream> #include< ...

  2. 3408: [Usaco2009 Oct]Heat Wave 热浪

    3408: [Usaco2009 Oct]Heat Wave 热浪 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 67  Solved: 55[Subm ...

  3. RIFF和WAVE音频文件格式

    RIFF file format RIFF全称为资源互换文件格式(Resources Interchange File Format),是Windows下大部分多媒体文件遵循的一种文件结构.RIFF文 ...

  4. 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 ...

  5. IEEE 802.11p (WAVE,Wireless Access in the Vehicular Environment)

    IEEE 802.11p(又称WAVE,Wireless Access in the Vehicular Environment)是一个由IEEE 802.11标准扩充的通讯协定.这个通讯协定主要用在 ...

  6. 【USACO 3.1】Stamps (完全背包)

    题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...

  7. USACO翻译:USACO 2013 NOV Silver三题

    USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...

  8. USACO翻译:USACO 2013 DEC Silver三题

    USACO 2013 DEC SILVER 一.题目概览 中文题目名称 挤奶调度 农场航线 贝西洗牌 英文题目名称 msched vacation shuffle 可执行文件名 msched vaca ...

  9. USACO翻译:USACO 2014 DEC Silver三题

    USACO 2014 DEC SILVER 一.题目概览 中文题目名称 回程 马拉松 奶牛慢跑 英文题目名称 piggyback marathon cowjog 可执行文件名 piggyback ma ...

随机推荐

  1. bnuoj 33647 Angry Grammar Nazi(字符串)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=33647 [题意]:字符串匹配,暴力配就行了 [题解]:截出单词,然后进行匹配就行了 [code]: ...

  2. HTTP - 内容编码

    HTTP 应用程序有时在发送之前需要对内容进行编码.例如,在把很大的 HTML 文档发送给通过慢速连接上来的客户端之前,服务器可能就会对它进行压缩,这样有助于减少传输实体的时间. 内容编码过程 内容编 ...

  3. 设计模式之单实例模式(Singleton)

    原理:将类的构造函数由pubic变为private或者protect,添加获取对象的public 成员函数,返回指向对象的静态指针. 首先来一段简单的代码实现 代码一 class Singleton ...

  4. 写一个函数,实现两个字符串的比较。即实现strcmp函数,s1=s2时返回0,s1!=s2时返回二者第一个不同字符的ASCII值。

    #include<stdio.h> #include<stdlib.h> int main(){ setvbuf(stdout,NULL,_IONBF,); ],s2[]; i ...

  5. java socket编程基础(转)

    一,网络编程中两个主要的问题 一个是如何准确的定位网络上一台或多台主机,另一个就是找到主机后如何可靠高效的进行数据传输. 在TCP/IP协议中IP层主要负责网络主机的定位,数据传输的路由,由IP地址可 ...

  6. DelayedOperationPurgatory之DelayedOperation pool

    purgatory就是炼狱的意思. 当一个DelayedOperation需要被delay时,它就被放到DelayedOperationPurgatory,相当于进行一个等待池.上一篇blog提到过, ...

  7. TYVJ P1016 装箱问题

    P1016 装箱问题 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 太原成成中学第2次模拟赛 第三道 描述 有一个箱子容量为v(正整数,o≤v≤20000) ...

  8. *[codility]AscendingPaths

    https://codility.com/programmers/challenges/magnesium2014 图形上的DP,先按照路径长度排序,然后依次遍历,状态是使用到当前路径为止的情况:每个 ...

  9. dubbo与zookeeper安装手册

    原文 示例提供者安装 (+) (#) 安装: wget http://code.alibabatech.com/mvn/releases/com/alibaba/dubbo-demo-provider ...

  10. Android getActionBar()报空指针异常

    1. 加载完视图后,再去获取: 写在setContentView()后面. 2.sdk版本: Actionbar的主题在3.0以后才有,使用的时候要确保,最低的版本不能小于3.0. <uses- ...