山东省2016acm省赛

A

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <list>
 5 #include <map>
 6 #include <stack>
 7 #include <vector>
 8 #include <cstring>
 9 #include <sstream>
10 #include <string>
11 #include <cmath>
12 #include <queue>
13 using namespace std;
14 #define clc(a,b) memset(a,b,sizeof(a))
15 #define inf 0x3f3f3f3f
16 const int N=10010;
17 const int MOD = 1e9+7;
18 #define LL long long
19 void fre() {
20     freopen("in.txt","r",stdin);
21 }
22 inline int r() {
23     int x=0,f=1;char ch=getchar();
24     while(ch>‘9‘||ch<‘0‘) {if(ch==‘-‘) f=-1;ch=getchar();}
25     while(ch>=‘0‘&&ch<=‘9‘) { x=x*10+ch-‘0‘;ch=getchar();}return x*f;
26 }
27
28 int main(){
29     int T;
30     T=r();
31     while(T--){
32         int x,y;
33         int ans;
34         x=r();
35         y=r();
36         if(x%y!=0)
37             ans=x/y+1;
38         else
39             ans=x/y;
40         cout<<ans<<endl;
41     }
42     return 0;
43 }

C

最短路

反向建边,记录当前点序号最小的前驱

  1 #include <iostream>
  2 #include <cstdio>
  3 #include <algorithm>
  4 #include <list>
  5 #include <map>
  6 #include <stack>
  7 #include <vector>
  8 #include <cstring>
  9 #include <sstream>
 10 #include <string>
 11 #include <cmath>
 12 #include <queue>
 13 #include <bits/stdc++.h>
 14 using namespace std;
 15 #define clc(a,b) memset(a,b,sizeof(a))
 16 #define inf 0x3f3f3f3f
 17 const int N=100010;
 18 const int MOD = 1e9+7;
 19 #define LL long long
 20 void fre() {
 21     freopen("in.txt","r",stdin);
 22 }
 23 inline int r() {
 24     int x=0,f=1;char ch=getchar();
 25     while(ch>‘9‘||ch<‘0‘) {if(ch==‘-‘) f=-1;ch=getchar();}
 26     while(ch>=‘0‘&&ch<=‘9‘) { x=x*10+ch-‘0‘;ch=getchar();}return x*f;
 27 }
 28 int n,m;
 29 struct node{
 30     int v,c;
 31     node(int vv,int cc){
 32        v=vv;
 33        c=cc;
 34     }
 35     node(){}
 36     bool operator <(const node &r) const{
 37         return c>r.c;
 38     }
 39 };
 40
 41 struct edge{
 42     int v,cost;
 43     edge(int vv=0,int ccost =0):v(vv),cost(ccost){}
 44 };
 45
 46 vector<edge>e[N];
 47 bool vis[N];
 48 int dist[N];
 49 int p[N];
 50 void dij(int start){
 51     clc(vis,false);
 52     for(int i=0;i<=n+1;i++) dist[i]=inf;
 53     priority_queue<node>q;
 54     while(!q.empty()) q.pop();
 55     dist[start]=0;
 56     q.push(node(start,0));
 57     node tmp;
 58     while(!q.empty()){
 59         tmp=q.top();
 60         q.pop();
 61         int u=tmp.v;
 62         if(vis[u]) continue;
 63         vis[u]=true;
 64         for(int i=0;i<e[u].size();i++){
 65              int v=e[u][i].v;
 66              int cost=e[u][i].cost;
 67              if(!vis[v]&&dist[v]>dist[u]+cost){
 68                 dist[v]=dist[u]+cost;
 69                 p[v]=u;
 70                 q.push(node(v,dist[v]));
 71              }
 72              else if(!vis[v]&&dist[v]==dist[u]+cost){
 73                 p[v]=min(p[v],u);
 74              }
 75         }
 76     }
 77 }
 78 void add(int u,int v,int w){
 79     e[u].push_back(edge(v,w));
 80 }
 81
 82 void init(){
 83     for(int i=0;i<=n+1;i++){
 84         e[i].clear();
 85     }
 86     clc(p,-1);
 87 }
 88
 89 int main(){
 90     // fre();
 91     int T;
 92     T=r();
 93     while(T--){
 94         n=r(),m=r();
 95         init();
 96         int u,v,w;
 97         while(m--){
 98             u=r(),v=r(),w=r();
 99             add(v,u,w);
100         }
101         dij(n+1);
102         if(dist[0]>=inf){
103             printf("-1\n");
104             continue;
105         }
106         else if(p[0]==n+1){
107             printf("0\n");
108             continue;
109         }
110         else
111             printf("%d\n",p[0]);
112     }
113     return 0;
114 }

D

归并排序技巧题

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <list>
 5 #include <map>
 6 #include <stack>
 7 #include <vector>
 8 #include <cstring>
 9 #include <sstream>
10 #include <string>
11 #include <cmath>
12 #include <queue>
13 using namespace std;
14 #define clc(a,b) memset(a,b,sizeof(a))
15 #define inf 0x3f3f3f3f
16 const int N=200010;
17 const int MOD = 1e9+7;
18 #define LL long long
19 void fre() {
20     freopen("in.txt","r",stdin);
21 }
22 inline int r() {
23     int x=0,f=1;char ch=getchar();
24     while(ch>‘9‘||ch<‘0‘) {if(ch==‘-‘) f=-1;ch=getchar();}
25     while(ch>=‘0‘&&ch<=‘9‘) { x=x*10+ch-‘0‘;ch=getchar();}return x*f;
26 }
27 struct node{
28     int s,w,num;
29 }p[N];
30 int n,R,q;
31 node a[N],b[N];
32
33 bool cmp(const node &a,const node &b){
34    return (a.s==b.s)?(a.num<b.num):(a.s>b.s);
35 }
36
37 void work(){
38     int ai=1,bi=1;
39     for(int i=1;i<=2*n;i+=2){
40         if(p[i].w>p[i+1].w){
41             p[i].s++;
42             a[ai++]=p[i];
43             b[bi++]=p[i+1];
44         }
45         else{
46             p[i+1].s++;
47             a[ai++]=p[i+1];
48             b[bi++]=p[i];
49         }
50     }
51     int i=1,j=1,k=1;
52     while(i<ai&&j<bi){
53         if(cmp(a[i],b[j])){
54             p[k++]=a[i++];
55         }
56         else
57             p[k++]=b[j++];
58     }
59     while(i<ai) p[k++]=a[i++];
60     while(j<bi) p[k++]=b[j++];
61 }
62
63 int main(){
64     // fre();
65     int T;
66     T=r();
67     while(T--){
68          n=r(),R=r(),q=r();
69          for(int i=1;i<=2*n;i++){
70             int x;
71             x=r();
72             p[i].s=x;
73             p[i].num=i;
74          }
75          for(int i=1;i<=2*n;i++){
76             int x;
77             x=r();
78             p[i].w=x;
79          }
80          sort(p+1,p+1+2*n,cmp);
81          for(int i=1;i<=R;i++){
82             work();
83          }
84          printf("%d\n",p[q].num);
85     }
86     return 0;
87 }

F

dp记忆话搜索

dp[i][j][k][inx][last]:当前三种水果分别有i j k个的时候且当前放第inx类的水果,持续了last天的方案数

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <list>
 5 #include <map>
 6 #include <stack>
 7 #include <vector>
 8 #include <cstring>
 9 #include <sstream>
10 #include <string>
11 #include <cmath>
12 #include <queue>
13 using namespace std;
14 #define clc(a,b) memset(a,b,sizeof(a))
15 #define inf 0x3f3f3f3f
16 const int N=10010;
17 const int MOD = 1e9+7;
18 #define LL long long
19 void fre() {
20     freopen("in.txt","r",stdin);
21 }
22 inline int r() {
23     int x=0,f=1;char ch=getchar();
24     while(ch>‘9‘||ch<‘0‘) {if(ch==‘-‘) f=-1;ch=getchar();}
25     while(ch>=‘0‘&&ch<=‘9‘) { x=x*10+ch-‘0‘;ch=getchar();}return x*f;
26 }
27
28 int num;
29 int dp[51][51][51][3][51];
30 int a[3],b[3];
31
32 int dfs(int n,int a0,int a1,int a2,int inx,int last){
33     LL ans=0;
34     if(dp[a0][a1][a2][inx][last]!=-1) return dp[a0][a1][a2][inx][last];
35     if(n==num) return dp[a0][a1][a2][inx][last]=1;
36     if(inx==-1){
37        if(b[0]>0&&a0>=1) ans+=dfs(n+1,a0-1,a1,a2,0,1);
38        if(b[1]>0&&a1>=1) ans+=dfs(n+1,a0,a1-1,a2,1,1);
39        if(b[2]>0&&a2>=1) ans+=dfs(n+1,a0,a1,a2-1,2,1);
40     }
41     else{
42        if(inx==0){
43           if(last+1<=b[0]&&a0>=1) ans+=dfs(n+1,a0-1,a1,a2,0,last+1);
44           if(b[1]>0&&a1>=1) ans+=dfs(n+1,a0,a1-1,a2,1,1);
45           if(b[2]>0&&a2>=1) ans+=dfs(n+1,a0,a1,a2-1,2,1);
46         }
47        else if(inx==1){
48           if(last+1<=b[1]&&a1>=1) ans+=dfs(n+1,a0,a1-1,a2,1,last+1);
49           if(b[0]>0&&a0>=1) ans+=dfs(n+1,a0-1,a1,a2,0,1);
50           if(b[2]>0&&a2>=1) ans+=dfs(n+1,a0,a1,a2-1,2,1);
51        }
52        else{
53           if(last+1<=b[2]&&a2>=1) ans+=dfs(n+1,a0,a1,a2-1,2,last+1);
54           if(b[0]>0&&a0>=1) ans+=dfs(n+1,a0-1,a1,a2,0,1);
55           if(b[1]>0&&a1>=1) ans+=dfs(n+1,a0,a1-1,a2,1,1);
56        }
57     }
58     ans%=MOD;
59     return dp[a0][a1][a2][inx][last]=ans;
60 }
61
62 int main(){
63     int T;
64     T=r();
65     while(T--){
66        clc(dp,-1);
67        for(int i=0;i<3;i++){
68           // scanf("%d",&a[i]);
69           int x;
70           x=r();
71           a[i]=x;
72        }
73        for(int i=0;i<3;i++){
74            // scanf("%d",&b[i]);
75            int x;
76            x=r();
77            b[i]=x;
78        }
79        num=a[0]+a[1]+a[2];
80        printf("%d\n",dfs(0,a[0],a[1],a[2],-1,0));
81     }
82     return 0;
83 }
时间: 2024-08-19 04:43:16

山东省2016acm省赛的相关文章

山东省第五届省赛总结

省赛终于过去了.感觉准备最充分的一次比赛比的最差,心里很伤心. 省赛之前,目标一直很明确,拿个金牌,向冠军冲刺.没想到最后拿了一个银牌.真的是讽刺. 热身赛的时候,一开始机器很搓.根本运行不了程序.然后就找来技术人员.技术人员搞了半个小时,也没搞出来个毛.最后还是机器自己莫名其妙的能用了. 然后我就上手敲B的随机题.没想到两次就过了,太开心了.然后专心看c题.一开始看出来的做法不对.后来离结束还有一点点的时候,终于想起来了正解.然后跟 scf一说,scf接着上手一敲.结果很对.然后果断交,然后就

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

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4124 L Median Time Limit: 1 Second      Memory Limit: 65536 KB Recall the definition of the median of  elements where  is odd: sort these elements and the median is the -th largest element.

2017年山东省ACM省赛总结

----但求努力到问心无愧 这次比赛我们是作为友谊队去的,本来我们队选拔赛成绩并不是很好,是去不了的,但伟大的教主大人牛逼地又要到了几个省赛友谊队的名额,才让我们有这次见识大场面比赛的机会,在这里我们先要感谢教主,还有就是感谢陪同的老师们,还有一直忙里忙外的负责人学长和同学们. 然后就是检讨我们自己了.这次比赛我们真的打的很不好,虽然比赛方有好多地方弄得有点欠缺.首先是热身赛,开始我们以为会有好多题,发下题目来看原来只有3个,好有三个题就三个题,那就做,但是我们还没开始看题,就意识到一个问题:这

第七届山东省ACM省赛

激动人心的省赛终于结束了…平静下来再回头看真的感觉一波三折…先是赛前毫无预兆的查出突发性耳聋…伴随而来的就是左耳听力下降.轻微耳鸣.极个别情况下的头晕…不过这都还好,毕竟药物可以恢复…热身赛只过了一道输出济南有多少泉水的水题,竟然第二次就猜对了,有个队交了四五十次…山师很心机的把酒店安排在了商业区.闹市和女子学院附近…(开个玩笑)为了不败第二天人品,我老老实实地待在了酒店,并没有出去嗨…正式赛开了…比赛打得多了,真的不紧张了…或许是喝了磊神指定饮料-红牛的作用…A是个签到题,我和Julyc讨论一

山东省第五届省赛回顾 Full Binary Tree

Full Binary Tree 题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2882 Time Limit: 2000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 In computer science, a binary tree is a tree data structure in which each node has at most tw

2016ACM省赛 ProblemD 猜字迷

1 #include<iostream> 2 #include<cstring> 3 #include<list> 4 using namespace std; 5 int main() 6 { 7 char a[1005],b[1005]; 8 while(cin>>a) 9 { 10 cin>>b; 11 list<char> s1(a,a+strlen(a)); 12 list<char> s2(b,b+strlen

2016ACM省赛 ProblemC 不同的衣服

1 #include<iostream> 2 #include<set> 3 using namespace std; 4 int main() 5 { 6 set<int> s; 7 int n; 8 while(cin>>n) 9 { 10 int k; 11 while(n--) 12 { 13 cin>>k; 14 s.insert(k); 15 } 16 cout<<s.size()<<endl; 17 s.cl

第二届山东省ACM省赛回顾 Crack Mathmen(打表)

Crack Mathmen 题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2165 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Since mathmen take security very seriously, they communicate in encrypted messages. They cipher

2012山东省ACM省赛-Pixel density

Pixel density 题目描述 Pixels per inch (PPI) or pixel density is a measurement of the resolution of devices in various contexts; typically computer displays, image scanners, and digital camera image sensors. Note, the unit is not square inches. Good qual