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. 2879: [Noi2012]美食节 - BZOJ

    Description CZ市为了欢迎全国各地的同学,特地举办了一场盛大的美食节.作为一个喜欢尝鲜的美食客,小M自然不愿意错过这场盛宴.他很快就尝遍了美食节所有的美食.然而,尝鲜的欲望是难以满足的.尽 ...

  2. 1562: [NOI2009]变换序列 - BZOJ

    Description Input Output Sample Input 5 1 1 2 2 1 Sample Output 1 2 4 0 3 HINT 30%的数据中N≤50:60%的数据中N≤ ...

  3. Linux "ls -l"文件列表权限详解

    ls Linux "ls -l"文件列表权限详解 1.使用 ls -l 命令 执行结果如下(/var/log) : drwxr-x--- root adm -- : apache2 ...

  4. Spring+Mybatis+Maven 整合配置

    <?xml version="1.0" encoding="UTF-8"?> <beans default-autowire="by ...

  5. 【转载】关于typedef的用法总结

    不管实在C还是C++代码中,typedef这个词都不少见,当然出现频率较高的还是在C代码中.typedef与#define有些相似,但更多的是不同,特别是在一些复杂的用法上,就完全不同了,看了网上一些 ...

  6. memcached-repcached

    memcached的复制功能 下载对应的repcached版本:http://sourceforge.jp/projects/sfnet_repcached/,必须版本对应才行 当前只支持到1.2.8 ...

  7. 基于Pre-Train的CNN模型的图像分类实验

    基于Pre-Train的CNN模型的图像分类实验  MatConvNet工具包提供了好几个在imageNet数据库上训练好的CNN模型,可以利用这个训练好的模型提取图像的特征.本文就利用其中的 “im ...

  8. 暑假集训单切赛第一场 CF 191A Dynasty Puzzles

    题意不说了,看原题吧,思路见代码: #include <iostream> #include <stdio.h> #include <string.h> #incl ...

  9. 深入浅出Java并发包—锁机制(一)

    前面我们看到了Lock和synchronized都能正常的保证数据的一致性(上文例子中执行的结果都是20000000),也看到了Lock的优势,那究竟他们是什么原理来保障的呢?今天我们就来探讨下Jav ...

  10. ASP.NET MVC 3 初认知

    什么是ASP.NET MVC 1. asp.net mvc 是微软官方提供的mvc模式编写asp.net web应用程序的框架. 2. 是微软既asp.net webForm 后的又一种开放方式,而非 ...