山东省2016acm省赛
A
水
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <list>
#include <map>
#include <stack>
#include <vector>
#include <cstring>
#include <sstream>
#include <string>
#include <cmath>
#include <queue>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=;
const int MOD = 1e9+;
#define LL long long
void fre() {
freopen("in.txt","r",stdin);
}
inline int r() {
int x=,f=;char ch=getchar();
while(ch>''||ch<'') {if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<='') { x=x*+ch-'';ch=getchar();}return x*f;
} int main(){
int T;
T=r();
while(T--){
int x,y;
int ans;
x=r();
y=r();
if(x%y!=)
ans=x/y+;
else
ans=x/y;
cout<<ans<<endl;
}
return ;
}
C
最短路
反向建边,记录当前点序号最小的前驱
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <list>
#include <map>
#include <stack>
#include <vector>
#include <cstring>
#include <sstream>
#include <string>
#include <cmath>
#include <queue>
#include <bits/stdc++.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=;
const int MOD = 1e9+;
#define LL long long
void fre() {
freopen("in.txt","r",stdin);
}
inline int r() {
int x=,f=;char ch=getchar();
while(ch>''||ch<'') {if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<='') { x=x*+ch-'';ch=getchar();}return x*f;
}
int n,m;
struct node{
int v,c;
node(int vv,int cc){
v=vv;
c=cc;
}
node(){}
bool operator <(const node &r) const{
return c>r.c;
}
}; struct edge{
int v,cost;
edge(int vv=,int ccost =):v(vv),cost(ccost){}
}; vector<edge>e[N];
bool vis[N];
int dist[N];
int p[N];
void dij(int start){
clc(vis,false);
for(int i=;i<=n+;i++) dist[i]=inf;
priority_queue<node>q;
while(!q.empty()) q.pop();
dist[start]=;
q.push(node(start,));
node tmp;
while(!q.empty()){
tmp=q.top();
q.pop();
int u=tmp.v;
if(vis[u]) continue;
vis[u]=true;
for(int i=;i<e[u].size();i++){
int v=e[u][i].v;
int cost=e[u][i].cost;
if(!vis[v]&&dist[v]>dist[u]+cost){
dist[v]=dist[u]+cost;
p[v]=u;
q.push(node(v,dist[v]));
}
else if(!vis[v]&&dist[v]==dist[u]+cost){
p[v]=min(p[v],u);
}
}
}
}
void add(int u,int v,int w){
e[u].push_back(edge(v,w));
} void init(){
for(int i=;i<=n+;i++){
e[i].clear();
}
clc(p,-);
} int main(){
// fre();
int T;
T=r();
while(T--){
n=r(),m=r();
init();
int u,v,w;
while(m--){
u=r(),v=r(),w=r();
add(v,u,w);
}
dij(n+);
if(dist[]>=inf){
printf("-1\n");
continue;
}
else if(p[]==n+){
printf("0\n");
continue;
}
else
printf("%d\n",p[]);
}
return ;
}
D
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <list>
#include <map>
#include <stack>
#include <vector>
#include <cstring>
#include <sstream>
#include <string>
#include <cmath>
#include <queue>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=;
const int MOD = 1e9+;
#define LL long long
void fre() {
freopen("in.txt","r",stdin);
}
inline int r() {
int x=,f=;char ch=getchar();
while(ch>''||ch<'') {if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<='') { x=x*+ch-'';ch=getchar();}return x*f;
}
struct node{
int s,w,num;
}p[N];
int n,R,q;
node a[N],b[N]; bool cmp(const node &a,const node &b){
return (a.s==b.s)?(a.num<b.num):(a.s>b.s);
} void work(){
int ai=,bi=;
for(int i=;i<=*n;i+=){
if(p[i].w>p[i+].w){
p[i].s++;
a[ai++]=p[i];
b[bi++]=p[i+];
}
else{
p[i+].s++;
a[ai++]=p[i+];
b[bi++]=p[i];
}
}
int i=,j=,k=;
while(i<ai&&j<bi){
if(cmp(a[i],b[j])){
p[k++]=a[i++];
}
else
p[k++]=b[j++];
}
while(i<ai) p[k++]=a[i++];
while(j<bi) p[k++]=b[j++];
} int main(){
// fre();
int T;
T=r();
while(T--){
n=r(),R=r(),q=r();
for(int i=;i<=*n;i++){
int x;
x=r();
p[i].s=x;
p[i].num=i;
}
for(int i=;i<=*n;i++){
int x;
x=r();
p[i].w=x;
}
sort(p+,p++*n,cmp);
for(int i=;i<=R;i++){
work();
}
printf("%d\n",p[q].num);
}
return ;
}
F
dp记忆话搜索
dp[i][j][k][inx][last]:当前三种水果分别有i j k个的时候且当前放第inx类的水果,持续了last天的方案数
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <list>
#include <map>
#include <stack>
#include <vector>
#include <cstring>
#include <sstream>
#include <string>
#include <cmath>
#include <queue>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=;
const int MOD = 1e9+;
#define LL long long
void fre() {
freopen("in.txt","r",stdin);
}
inline int r() {
int x=,f=;char ch=getchar();
while(ch>''||ch<'') {if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<='') { x=x*+ch-'';ch=getchar();}return x*f;
} int num;
int dp[][][][][];
int a[],b[]; int dfs(int n,int a0,int a1,int a2,int inx,int last){
LL ans=;
if(dp[a0][a1][a2][inx][last]!=-) return dp[a0][a1][a2][inx][last];
if(n==num) return dp[a0][a1][a2][inx][last]=;
if(inx==-){
if(b[]>&&a0>=) ans+=dfs(n+,a0-,a1,a2,,);
if(b[]>&&a1>=) ans+=dfs(n+,a0,a1-,a2,,);
if(b[]>&&a2>=) ans+=dfs(n+,a0,a1,a2-,,);
}
else{
if(inx==){
if(last+<=b[]&&a0>=) ans+=dfs(n+,a0-,a1,a2,,last+);
if(b[]>&&a1>=) ans+=dfs(n+,a0,a1-,a2,,);
if(b[]>&&a2>=) ans+=dfs(n+,a0,a1,a2-,,);
}
else if(inx==){
if(last+<=b[]&&a1>=) ans+=dfs(n+,a0,a1-,a2,,last+);
if(b[]>&&a0>=) ans+=dfs(n+,a0-,a1,a2,,);
if(b[]>&&a2>=) ans+=dfs(n+,a0,a1,a2-,,);
}
else{
if(last+<=b[]&&a2>=) ans+=dfs(n+,a0,a1,a2-,,last+);
if(b[]>&&a0>=) ans+=dfs(n+,a0-,a1,a2,,);
if(b[]>&&a1>=) ans+=dfs(n+,a0,a1-,a2,,);
}
}
ans%=MOD;
return dp[a0][a1][a2][inx][last]=ans;
} int main(){
int T;
T=r();
while(T--){
clc(dp,-);
for(int i=;i<;i++){
// scanf("%d",&a[i]);
int x;
x=r();
a[i]=x;
}
for(int i=;i<;i++){
// scanf("%d",&b[i]);
int x;
x=r();
b[i]=x;
}
num=a[]+a[]+a[];
printf("%d\n",dfs(,a[],a[],a[],-,));
}
return ;
}
山东省2016acm省赛的更多相关文章
- 第七届山东省ACM省赛
激动人心的省赛终于结束了…平静下来再回头看真的感觉一波三折…先是赛前毫无预兆的查出突发性耳聋…伴随而来的就是左耳听力下降.轻微耳鸣.极个别情况下的头晕…不过这都还好,毕竟药物可以恢复…热身赛只过了一道 ...
- 一场刺激的游戏——很文艺的山东省第四届ACM赛总结(菜鸟版)
人生就像一个个节点,节点中或许有成功,失败,满足,遗憾,但是只要它是不可复制的,在日后,便是美好. ...
- 第十届山东省acm省赛补题(1)
今天第一场个人训练赛的题目有点恐怖啊,我看了半个小时多硬是一道都不会写.我干脆就直接补题去了.... 先补的都是简单题,难题等我这周末慢慢来吧... A Calandar Time Limit: 1 ...
- 2018年第九届山东省ACM省赛总结
去年打完区域赛之后,面对着两个队友都去找实习的情况,我自己对今年省赛还是有点慌的.不只一次的像我的队友说明自己很慌,但是老曹跟会长都说:“没事,慌啥!”前几场训练赛因为老曹跟秋洁有面试有时候只能一个人 ...
- 2019山东省ACM省赛菜鸡的赛后总结
省赛总结 2019-05-13 21:27:40 虽然第一次就死的这么难看,但是的确发现了很多问题,我想这是未来我和我的队友要解决的,而不是去难过,去感慨自己是有多菜.在大一训练结束马上参加暑假集训的 ...
- 2018山东省ACM省赛G题-Game
Alice and Bob are playing a stone game. There are n piles of stones. In each turn, a player can remo ...
- 山东省第四届省赛 E-Mountain Subsequences
Description Coco is a beautiful ACMer girl living in a very beautiful mountain. There are many trees ...
- 山东省第八届省赛 A:Return of the Nim(尼姆+威佐夫)
Problem Description Sherlock and Watson are playing the following modified version of Nim game: Ther ...
- 第十届山东省acm省赛补题(2)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4124 L Median Time Limit: 1 Second ...
随机推荐
- C#学习笔记(三)
1.我们在Main()函数中,调用Test()函数,我们管Main()函数称之为调用者,管Test()函数称之为被调用者.如果被调用者想要得到调用者的值:1).传递参数.2).使用静态字段来模拟全局变 ...
- 团体程序设计天梯赛-练习集L1-016. 查验身份证
L1-016. 查验身份证 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一个合法的身份证号码由17位地区.日期编号和顺序编号 ...
- 酷摄影:关于梦 - Miki takahashi
这组摄影来自于日本东京摄影师 Miki takahashi 是一组双重曝光摄影,分开看也许很平常,但是结合在一起却非常有韵味. [gallery]
- 非常好的Demo网站
http://www.xdemo.org/
- thinkphp 减少文件目录
配置 'TMPL_FILE_DEPR'=>'_' 于是模板文件的格式为如:index_index.html,index_show.html .代替原来的目录结构:/index/index.htm ...
- SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-006-Pizza例子的支付流程
一. 1. 2.payment-flow.xml <?xml version="1.0" encoding="UTF-8"?> <flow x ...
- Microsoft SQL Server 2012 数据库安装图解教程
本文部分引用以下文章: SQL Server 2012 安装图解教程(附sql2012下载地址)_MsSql_脚本之家 http://www.jb51.net/article/36049.htm SQ ...
- Java读写Windows共享文件夹 .
版权声明:本文为博主原创文章,未经博主允许不得转载. 项目常常需要有访问共享文件夹的需求,例如共享文件夹存储照片.文件等.那么如何使用Java读写Windows共享文件夹呢? Java可以使用JCIF ...
- Linux的终端与进程
原文链接:http://os.51cto.com/art/201104/256477.htm Linux的普通进程(守护进程除外) 是终端的子进程,进程的存在要依赖终端为其提供空间包括标准输入.标准输 ...
- linux系统灵活运用灯[android课程3]
1,文件如何生成: ----- ---- (二),把hello例子贴过来后,编译问题: 在编译Android 4.0驱动的时候,使用到了proc_dir_entry结构体中的owner成员,但是编译的 ...