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省赛的更多相关文章

  1. 第七届山东省ACM省赛

    激动人心的省赛终于结束了…平静下来再回头看真的感觉一波三折…先是赛前毫无预兆的查出突发性耳聋…伴随而来的就是左耳听力下降.轻微耳鸣.极个别情况下的头晕…不过这都还好,毕竟药物可以恢复…热身赛只过了一道 ...

  2. 一场刺激的游戏——很文艺的山东省第四届ACM赛总结(菜鸟版)

               人生就像一个个节点,节点中或许有成功,失败,满足,遗憾,但是只要它是不可复制的,在日后,便是美好.                                         ...

  3. 第十届山东省acm省赛补题(1)

    今天第一场个人训练赛的题目有点恐怖啊,我看了半个小时多硬是一道都不会写.我干脆就直接补题去了.... 先补的都是简单题,难题等我这周末慢慢来吧... A Calandar Time Limit: 1 ...

  4. 2018年第九届山东省ACM省赛总结

    去年打完区域赛之后,面对着两个队友都去找实习的情况,我自己对今年省赛还是有点慌的.不只一次的像我的队友说明自己很慌,但是老曹跟会长都说:“没事,慌啥!”前几场训练赛因为老曹跟秋洁有面试有时候只能一个人 ...

  5. 2019山东省ACM省赛菜鸡的赛后总结

    省赛总结 2019-05-13 21:27:40 虽然第一次就死的这么难看,但是的确发现了很多问题,我想这是未来我和我的队友要解决的,而不是去难过,去感慨自己是有多菜.在大一训练结束马上参加暑假集训的 ...

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

  7. 山东省第四届省赛 E-Mountain Subsequences

    Description Coco is a beautiful ACMer girl living in a very beautiful mountain. There are many trees ...

  8. 山东省第八届省赛 A:Return of the Nim(尼姆+威佐夫)

    Problem Description Sherlock and Watson are playing the following modified version of Nim game: Ther ...

  9. 第十届山东省acm省赛补题(2)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4124 L Median Time Limit: 1 Second      ...

随机推荐

  1. Windows2003/2008/2008 R2下易语言点支持库配置就退出的问题

    问题: 请问一个问题,我的电脑上win2003系统的,安装了易语言后,一点支持库配置就会自动退出.这是为什么啊? 解决方法如下: 删除 lib下的wmp.npk,重新打开易语言就可以了.

  2. PAT-乙级-1043. 输出PATest(20)

    1043. 输出PATest(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一个长度不超过10000 ...

  3. The 5th Zhejiang Provincial Collegiate Programming Contest------ProblemK:Kinds of Fuwas

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1974 题意:问四个角都有同一个福娃的矩形有多少个. #include<b ...

  4. hdu 1213

    简单并查集 #include <cstdio> #include <cstring> #define maxn 30005 int fa[maxn],ans[maxn],n,m ...

  5. 不定长内存池之apr_pool

    内存池可有效降低动态申请内存的次数,减少与内核态的交互,提升系统性能,减少内存碎片,增加内存空间使用率,避免内存泄漏的可能性,这么多的优点,没有理由不在系统中使用该技术. 内存池分类: 1.      ...

  6. JNDI:对java:comp/env的研究

    这两天研究了一下 context.lookup("java:comp/env/XXX")和直接context.lookup("XXX")的区别 网上关于这两个的 ...

  7. Java Web开发 之小张老师总结GET和POST区别

    get和post区别1.传输方式不同,get在request-line中传输(即在URL中传输).post在request-line及 request-body中传输(可认为隐藏传输)2.get传输长 ...

  8. mysql查看数据库命令

    mysql查看数据库命令 打开的数据库的命令 mysql> use mysql Database changed 查看数据库的命令 mysql> show databases; 查看数据表 ...

  9. P55、面试题6:重建二叉树

    题目:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字,例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2, ...

  10. ssh-keygen的使用方法

    一.概述 1.就是为了让两个linux机器之间使用ssh不需要用户名和密码.采用了数字签名RSA或者DSA来完成这个操作 2.模型分析 假设 A (192.168.20.59)为客户机器,B(192. ...