山东省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 ...
随机推荐
- How to Cope with Deadlocks
http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html How to Cope with Deadlocks This section ...
- 【无聊放个模板系列】HDU 3506 (四边形不等式优化DP-经典石子合并问题[环形])
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- Linux系统下如何配置SSH?如何开启SSH?
SSH作为Linux远程连接重要的方式,如何配置安装linux系统的SSH服务,如何开启SSH?下面来看看吧(本例为centos系统演示如何开启SSH服务). 查询\安装SSH服务 1.登陆linux ...
- Weblogic下部署的应用,当更新文件时需要重新安装部署
JSP页面检查(秒):-1 Servlet重新加载检查(秒):-1 -1说明从不检查,故当更新文件时,需要重新部署,或重新安装部署.
- HeadFirst设计模式之工厂模式
一. 1."工厂模式"不是种真正的设计模式,而是一种编程术语 2.The Factory Method Pattern defi nes an interface for crea ...
- SPRING IN ACTION 第4版笔记-第九章Securing web applications-002-把用户数据存在memory里(AuthenticationManagerBuilder、 UserDetailsManagerConfigurer.UserDetailsBuilder)
Spring Security is extremely flexible and is capable of authenticating users against virtually any d ...
- QPushButton 的checkable 属性
只有setCheckable(true),这个button才能发射 toggle(bool) 信号. 而toggle(bool)代表了button 按下,弹起的状态像0,1的切换开关.
- Hadoop常用命令汇总
启动Hadoop 进入HADOOP_HOME目录. 执行sh bin/start-all.sh 关闭Hadoop 进入HADOOP_HOME目录. 执行sh bin/stop-all.sh 1.查看指 ...
- (转)Decision Tree
Decision Tree:Analysis 大家有没有玩过猜猜看(Twenty Questions)的游戏?我在心里想一件物体,你可以用一些问题来确定我心里想的这个物体:如是不是植物?是否会飞?能游 ...
- Java汉字排序(3)按笔划排序
对于包含汉字的字符串来说,排序的方式主要有两种:一种是拼音,一种是笔画. 本文就讲述如何实现按笔划排序的比较器(Comparator). 作者:Jeff 发表于:2007年12月21日 11:27 最 ...