USACO2018DEC GOLD
好简单啊。。
T1裸分层图最短路。
T2裸容斥。
T3更水的DP。
代码
T1
#include <bits/stdc++.h>
#define rin(i,a,b) for(register int i=(a);i<=(b);++i)
#define irin(i,a,b) for(register int i=(a);i>=(b);--i)
#define trav(i,a) for(register int i=head[a];i;i=e[i].nxt)
typedef long long LL;
using std::cin;
using std::cout;
using std::endl;
inline int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int MAXN=50005;
const int MAXM=100005;
int n,m,k,ecnt,head[MAXN<<1];
LL dis[MAXN<<1];
bool book[MAXN<<1];
struct Edge{
int to,nxt,w;
}e[MAXM*4+MAXN];
inline void add_edge(int bg,int ed,int val){
++ecnt;
e[ecnt].to=ed;
e[ecnt].nxt=head[bg];
e[ecnt].w=val;
head[bg]=ecnt;
}
std::queue<int> q;
void spfa(){
while(!q.empty()) q.pop();
memset(dis,0x3f,sizeof dis);
dis[n]=0;
q.push(n);
book[n]=true;
while(!q.empty()){
int x=q.front();
trav(i,x){
int ver=e[i].to;
if(dis[ver]>dis[x]+e[i].w){
dis[ver]=dis[x]+e[i].w;
if(!book[ver]){
q.push(ver);
book[ver]=true;
}
}
}
q.pop();
book[x]=false;
}
}
int main(){
n=read(),m=read(),k=read();
rin(i,1,m){
int u=read(),v=read(),w=read();
add_edge(u,v,w);
add_edge(v,u,w);
add_edge(u+n,v+n,w);
add_edge(v+n,u+n,w);
}
rin(i,1,k){
int x=read(),y=read();
add_edge(x,x+n,-y);
}
spfa();
rin(i,1,n-1){
if(dis[n+i]<=dis[i]) printf("1\n");
else printf("0\n");
}
return 0;
}
T2
#include <bits/stdc++.h>
#define rin(i,a,b) for(register int i=(a);i<=(b);++i)
#define irin(i,a,b) for(register int i=(a);i>=(b);--i)
#define trav(i,a) for(register int i=head[a];i;i=e[i].nxt)
typedef long long LL;
using std::cin;
using std::cout;
using std::endl;
inline int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
typedef std::pair<int,int> tw;
typedef std::pair<int,tw> tr;
typedef std::pair<tw,tw> fo;
typedef std::pair<tw,tr> fi;
inline tw mktw(int x,int y){
return (tw){x,y};
}
inline tr mktr(int x,int y,int z){
return (tr){x,mktw(y,z)};
}
inline fo mkfo(int x,int y,int z,int v){
return (fo){mktw(x,y),mktw(z,v)};
}
inline fi mkfi(int x,int y,int z,int v,int w){
return (fi){mktw(x,y),mktr(z,v,w)};
}
int n;
int mp1[1000005];
std::map<tw,int> mp2;
std::map<tr,int> mp3;
std::map<fo,int> mp4;
std::map<fi,int> mp5;
int main(){
n=read();
rin(i,1,n){
int a[6];
a[1]=read(),a[2]=read(),a[3]=read(),a[4]=read(),a[5]=read();
std::sort(a+1,a+6);
int x=a[1],y=a[2],z=a[3],v=a[4],w=a[5];
++mp1[x];
++mp1[y];
++mp1[z];
++mp1[v];
++mp1[w];
++mp2[mktw(x,y)];
++mp2[mktw(x,z)];
++mp2[mktw(x,v)];
++mp2[mktw(x,w)];
++mp2[mktw(y,z)];
++mp2[mktw(y,v)];
++mp2[mktw(y,w)];
++mp2[mktw(z,v)];
++mp2[mktw(z,w)];
++mp2[mktw(v,w)];
++mp3[mktr(x,y,z)];
++mp3[mktr(x,y,v)];
++mp3[mktr(x,y,w)];
++mp3[mktr(x,z,v)];
++mp3[mktr(x,z,w)];
++mp3[mktr(x,v,w)];
++mp3[mktr(y,z,v)];
++mp3[mktr(y,z,w)];
++mp3[mktr(y,v,w)];
++mp3[mktr(z,v,w)];
++mp4[mkfo(x,y,z,v)];
++mp4[mkfo(x,y,z,w)];
++mp4[mkfo(x,y,v,w)];
++mp4[mkfo(x,z,v,w)];
++mp4[mkfo(y,z,v,w)];
++mp5[mkfi(x,y,z,v,w)];
}
LL ans=0;
rin(i,1,1000000) ans+=1ll*mp1[i]*(mp1[i]-1)/2;
for(register std::map<tw,int>::iterator it=mp2.begin();it!=mp2.end();++it) ans-=1ll*it->second*(it->second-1)/2;
for(register std::map<tr,int>::iterator it=mp3.begin();it!=mp3.end();++it) ans+=1ll*it->second*(it->second-1)/2;
for(register std::map<fo,int>::iterator it=mp4.begin();it!=mp4.end();++it) ans-=1ll*it->second*(it->second-1)/2;
for(register std::map<fi,int>::iterator it=mp5.begin();it!=mp5.end();++it) ans+=1ll*it->second*(it->second-1)/2;
printf("%lld\n",1ll*n*(n-1)/2-ans);
return 0;
}
T3
#include <bits/stdc++.h>
#define rin(i,a,b) for(register int i=(a);i<=(b);++i)
#define irin(i,a,b) for(register int i=(a);i>=(b);--i)
#define trav(i,a) for(register int i=head[a];i;i=e[i].nxt)
typedef long long LL;
using std::cin;
using std::cout;
using std::endl;
inline int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int MAXN=10005;
const int MAXK=1005;
int n,k,a[MAXN],f[MAXN];
int main(){
n=read(),k=read();
rin(i,1,n) a[i]=read();
f[0]=0;
rin(i,1,n){
int temp=0;
irin(j,i,std::max(i-k+1,1)){
temp=std::max(temp,a[j]);
f[i]=std::max(f[i],f[j-1]+temp*(i-j+1));
}
}
printf("%d\n",f[n]);
return 0;
}
USACO2018DEC GOLD的更多相关文章
- Baskets of Gold Coins_暴力
Problem Description You are given N baskets of gold coins. The baskets are numbered from 1 to N. In ...
- [UCSD白板题] Take as Much Gold as Possible
Problem Introduction This problem is about implementing an algorithm for the knapsack without repeti ...
- XidianOJ 1120 Gold of Orz Pandas
题目描述 Orz Panda is addicted to one RPG game. To make his character stronger, he have to fulfil tasks ...
- POJ 3274 Gold Balanced Lineup
Gold Balanced Lineup Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10924 Accepted: 3244 ...
- 哈希-Gold Balanced Lineup 分类: POJ 哈希 2015-08-07 09:04 2人阅读 评论(0) 收藏
Gold Balanced Lineup Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13215 Accepted: 3873 ...
- Gold Coins 分类: POJ 2015-06-10 15:04 16人阅读 评论(0) 收藏
Gold Coins Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21767 Accepted: 13641 Desc ...
- 2012 #5 Gold miner
Gold miner Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Pots of gold game:看谁拿的钱多
问题描述: Pots of gold game: Two players A & B. There are pots of gold arranged in a line, each cont ...
- [LOJ 1030] Discovering Gold
B - Discovering Gold Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
随机推荐
- jQuery扁平化风格手风琴菜单
在线演示 本地下载
- redis 学习(9)-- redis 客户端 -- redis-py
redis 客户端 -- redis-py 简介 关于 redis 的各种客户端,我们可以在官网上寻找并使用,比如我这里的 python 客户端,可以在官网上找到:redis-client . 获取 ...
- luogu题解 UVA534 【Frogger--最小瓶颈边
题目链接: https://www.luogu.org/problemnew/show/UVA534 Update 6.18 多点对最短瓶颈路算法:https://www.cnblogs.com/Ry ...
- VS 2005 \ 2008 "当前不会命中断点。源代码与原始版本不同"解决方法
全选CPP文件内容, 选择 “编辑”-“高级”-“设置选定内容的格式”,保存,重新编译! 快捷键 ctrl + A 全选文件内容后 按 ctrl + K ,F OK!
- 分布式的几件小事(九)zookeeper都有哪些使用场景
1.zookeeper介绍 ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提 ...
- vue-复制功能插件-兼容性最好的插件
记录给自己用,不进同一次坑: https://github.com/Inndy/vue-clipboard2
- Java 计算两点间的全部路径(二)
一.有向线段,存储开始点与结束点 /** * 有方向的线段 * * @author Gm * */ public class DirectionLine implements Cloneable { ...
- ORACLE (BLOB、CLOB、NCLOB、BFILE)
LOB类型 内置的LOB数据类型包括BLOB.CLOB.NCLOB.BFILE(外部存储)的大型化和非结构化数据,如文本.图像.视屏.空间数据存储.BLOB.CLOB.NCLOB类型 4.1 CLOB ...
- 多个分组树分别实现单选jq+angular
$scope.seletedGroup=[];var $li=$("#departmentsContainer>ol>li");$.each($li,function( ...
- h5图片展示和ajax上传
<img src="" id="img"/> <script src="http://static.lamian.tv//pc/pu ...