CDQZ Day5

1
DP #1
题目名称 题目名称
匹配

路径
染色
输入文件名 输入文件名
match.in.in.in
block.in
path.in
paint.in
输出文件名 输出文件名
match.out.out.out.out
block.out
path.out
paint.out
每个测试点时 每个测试点时 每个测试点时 每个测试点时 每个测试点时 每个测试点时 限
1s
1s
1s
1.5 s
测试点数目 测试点数目
10
10
10
10
每个测试点分 每个测试点分 每个测试点分 每个测试点分 每个测试点分 每个测试点分 值
10
10
10
10
内存限制 内存限制
256 M
256M
256 M
256 M
是否有部分 是否有部分 是否有部分




题目类型 题目类型
传统
传统
传统
传统
注意:代码长度限制均为 注意:代码长度限制均为 注意:代码长度限制均为 注意:代码长度限制均为 注意:代码长度限制均为 注意:代码长度限制均为 64K ,不开 ,不开 O2 。
2
1 匹配(match.c/cpp/pas)
1.1 题目描述
现在有一排花和一排花盆,每株花有互不相同的标号,花盆也有互不相同的标号,标号
均为1~n,也就是有 n 株花和 n 个花盆。
花与花盆共排成了上下两排,现在希望为尽可能多的花匹配一个对应的花盆,匹配时将
为其连上一条直线。要求匹配所产生的直线互不相交,并且为了和谐,匹配的花与花盆标号
应当相同。
问最多能匹配的对数。
1.2 输入格式
第一行为一个整数n ,分别表示 A、B 的序列长度。
接下来一行 n 个数,表示序列 A。
接下来一行 n 个数,表示序列 B。
1.3 输出格式
输出一行一个整数,表示最多能匹配的对数。
1.4 样例输入
3
1 2 3
1 3 2
1.5 样例输出
2
1.6 数据范围与约定
对于20%的数据,n <= 300。
对于40%的数据,n <= 1000。
对于100%的数据,n <= 100000。
3
2 2 块 (block.c/cpp/pas) .c/cpp/pas) .c/cpp/pas)
2.1 .1 .1 题目描述 题目描述
有一棵 n个结点 个结点 的树,结点从 ,结点从 ,结点从 1到 n标号 。现在 希望 删去 最少 的边,使得 出现 一个 大 小为 K 的联通 块。
2.2 .2 .2 输入格式 输入格式
第一行 两个整数 n, K,代表 树的结点个数 结点个数 ,以及 希望 出现 大小 为 K的联通 块。
接下来 接下来 n-1行,每行 两个 数 u,v,表示 u、v之间 有一条 连边 。
2.3 .3 .3 输出格式 输出格式
输出 一行 一个 数,表示 最少 删去 的边数 。
2.4 .4 .4 样例输入 样例输入
11 611 611 6
1 21 2
1 31 3
1 41 4
1 51 5
2 62 6
2 72 7
2 82 8
4 94 9
4 104 10 4 10
4 114 11 4 11
2.5 .5 .5 样例输出 样例输出
2
2.6 .6 .6 数据范围与约定 数据范围与约定 数据范围与约定 数据范围与约定
对于 20%的数据,保证 %的数据,保证 %的数据,保证 %的数据,保证 1 <= n <= 18。
对于 50%的数据,保证 %的数据,保证 %的数据,保证 %的数据,保证 1 <= n <= 200。
对于 100%的数据,保证 %的数据,保证 %的数据,保证 %的数据,保证 1 <= n <= 1000,1<=K<=n。
4
3 路径 (path.c/cpp/pas) .c/cpp/pas) .c/cpp/pas)
3.1 .1 .1 题目描述 题目描述
给出 一个有 n 个点 m 条边的有向图,每个 条边的有向图,每个 条边的有向图,每个 条边的有向图,每个 条边的有向图,每个 条边的有向图,每个 结点 上有一个 小写 字母 ,定义一条路径的权 ,定义一条路径的权 ,定义一条路径的权 ,定义一条路径的权 ,定义一条路径的权 值是这条路径 值是这条路径 值是这条路径 上出现次数最多的字母个,求这图 出现次数最多的字母个,求这图 出现次数最多的字母个,求这图 出现次数最多的字母个,求这图 出现次数最多的字母个,求这图 出现次数最多的字母个,求这图 出现次数最多的字母个,求这图 出现次数最多的字母个,求这图 最大权值的路径。 最大权值的路径。 最大权值的路径。 最大权值的路径。 最大权值的路径。
3.2 .2 .2 输入格式 输入格式
第一行 两个 整数 n, m,表示 结点 数和边数 。
第二行 一个 不带 空格 的字符串 字符串 ,第 i 个字符 表示 第 i 个结点 对应 的小写 字母 。
3.3 .3 .3 输出格式 输出格式
输出 一行 一个 整数 ,表示 最大 权值 的路径 的权值 ,若为 无穷大 无穷大 则输出 -1 。
3.4 .4 .4 样例输入 样例输入
5 45 4
abaca abaca
1 21 2
1 31 3
3 43 4
4 54 5
3.5 .5 .5 样例输出 样例输出
3
3 .6 .6 .6 数据范围 与约定
对于 20%的数据,保证 %的数据,保证 %的数据,保证 %的数据,保证 1 <= n, m <= 10。
对于 50%的数据 ,保证 1<=n, m<=5000。
对于 100%的数据,保证 %的数据,保证 %的数据,保证 %的数据,保证 1<=n, m<=300000 。
5
4 染色 (paint.c/cpp/pas) .c/cpp/pas) .c/cpp/pas)
4.1 .1 .1 题目描述 题目描述
一个木板上有 一个木板上有 一个木板上有 n 个格子,一开始均无色(颜为 个格子,一开始均无色(颜为 个格子,一开始均无色(颜为 个格子,一开始均无色(颜为 个格子,一开始均无色(颜为 个格子,一开始均无色(颜为 个格子,一开始均无色(颜为 个格子,一开始均无色(颜为 个格子,一开始均无色(颜为 0)。现在要进行 )。现在要进行 )。现在要进行 )。现在要进行 )。现在要进行 K 次染色,每 次染色,每 次染色,每 次告 诉你 染区间 染区间 [li,ri],颜色为 ,颜色为 ci。 颜色会被覆盖。 颜色会被覆盖。 颜色会被覆盖。 颜色会被覆盖问最后的木板上所有格子颜色。 问最后的木板上所有格子颜色。 问最后的木板上所有格子颜色。 问最后的木板上所有格子颜色。 问最后的木板上所有格子颜色。 问最后的木板上所有格子颜色。 问最后的木板上所有格子颜色。
4.2 .2 .2 输入格式 输入格式
第一行两个整数 第一行两个整数 第一行两个整数 n; Kn; Kn; K ,表示格子数和染色次。 ,表示格子数和染色次。 ,表示格子数和染色次。 ,表示格子数和染色次。 ,表示格子数和染色次。 ,表示格子数和染色次。 ,表示格子数和染色次。
接下来 K 行,每三个整数 行,每三个整数 行,每三个整数 行,每三个整数 行,每三个整数 li,ri,ci,表示染色 区间和颜,表示染色 区间和颜,表示染色 区间和颜,表示染色 区间和颜,表示染色
区间和颜4.3 .3 .3 输出格式 输出格式
输出 一行 n 个整数,输出这木板上的所有格子颜色。 个整数,输出这木板上的所有格子颜色。 个整数,输出这木板上的所有格子颜色。 个整数,输出这木板上的所有格子颜色。 个整数,输出这木板上的所有格子颜色。 个整数,输出这木板上的所有格子颜色。 个整数,输出这木板上的所有格子颜色。 个整数,输出这木板上的所有格子颜色。 个整数,输出这木板上的所有格子颜色。
4.4 .4 .4 样例输入 样例输入
4 2
1 2 4
2 4 1
4.5 .5 .5 样例输出 样例输出
4 1 1 1
4.6 .6 .6 数据范围与约定 数据范围与约定 数据范围与约定 数据范围与约定
对于 10%的数据,保证 %的数据,保证 %的数据,保证 %的数据,保证 n <= 100。
对于 40%的数据 ,保证 n, K<=100000。
对于 100%的数据,保证 %的数据,保证 %的数据,保证 %的数据,保证 1<=n, K<=1000000 ,1<=ci<=1000000。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<vector>
 7 #define R(a,b,c) for(register int (a)=(b);(a)<=(c);++(a))
 8 #define nR(a,b,c) for(register int (a)=(b);(a)>=(c);--(a))
 9 #define Ii inline int
10 #define Iv inline void
11 #define Il inline long long
12 #define Ib inline bool
13 #define INF 0x7ffffff
14 #define re register
15 #define ll long long
16 #define Max(a,b) ((a)>(b)?(a):(b))
17 #define Min(a,b) ((a)<(b)?(a):(b))
18 #define Cmin(a,b) ((a)=(a)<(b)?(a):(b))
19 #define Cmax(a,b) ((a)=(a)>(b)?(a):(b))
20 #define Fill(a,b) memset((a),(b),sizeof((a)))
21 #define D_e_Line printf("\n-------------\n");
22 #define D_e(x) printf("\n______%d_______\n",x)
23 #define Pause system("pause")
24 using namespace std;
25 const int N=100005;
26 Ii read(){
27     int s=0,f=1;char c;
28     for(c=getchar();c>'9'||c<'0';c=getchar())if(c=='-')f=-1;
29     while(c>='0'&&c<='9')s=s*10+(c^'0'),c=getchar();
30     return s*f;
31 }
32 Iv print(int x){
33     if(x<0)putchar('-'),x=-x;
34     if(x>9)print(x/10);
35     putchar(x%10^'0');
36 }
37 int a[N],f[N];
38 #define ON_JUDGE
39 int main(){
40 #ifdef ON_JUDGE
41     freopen("match.in","r",stdin),freopen("match.out","w",stdout);
42 #endif
43     int n=read();
44     R(i,1,n)
45         a[read()]=i;
46     int len=0;
47     R(i,1,n){
48         int x=a[read()];
49         if(x>=f[len])
50             f[++len]=x;
51         else{
52             int l=0,r=len;
53             while(l<=r){
54                 int mid=l+r>>1;
55                 f[mid]>=x?
56                     r=mid-1: 
57                     l=mid+1;
58             }
59             f[l]=x;
60         }
61     }
62     print(len);
63     return 0;
64 }
65 /*
66 4
67 1 0 9 7
68 1 9 7 0
69 
70 5
71 1 1 1 0 2
72 1 1 0 1 2
73 
74 6
75 2 3 9 7 5 7
76 3 4 7 8 5 7
77 
78 7
79 4 5 2 3 6 7 1
80 1 3 4 2 5 6 1
81 
82 7
83 1 3 2 4 5 6 7
84 3 1 4 2 6 5 7
85 */
match_My_CreatOnContest.cpp
  1 #include<cstdio>
  2 #include<cstring>
  3 #include<iostream>
  4 #include<algorithm>
  5 #include<cmath>
  6 #include<vector>
  7 #include<bitset>
  8 #define R(a,b,c) for(register int (a)=(b);(a)<=(c);++(a))
  9 #define nR(a,b,c) for(register int (a)=(b);(a)>=(c);--(a))
 10 #define Ii inline int
 11 #define Iv inline void
 12 #define Il inline long long
 13 #define Ib inline bool
 14 #define INF 0x7ffffff
 15 #define re register
 16 #define ll long long
 17 #define Max(a,b) ((a)>(b)?(a):(b))
 18 #define Min(a,b) ((a)<(b)?(a):(b))
 19 #define Cmin(a,b) ((a)=(a)<(b)?(a):(b))
 20 #define Cmax(a,b) ((a)=(a)>(b)?(a):(b))
 21 #define Fill(a,b) memset((a),(b),sizeof((a)))
 22 #define D_e_Line printf("\n-------------\n");
 23 #define D_e(x) printf("\n______%d_______\n",x)
 24 #define Pause system("pause")
 25 using namespace std;
 26 const int N=2005;
 27 Ii read(){
 28     int s=0,f=1;char c;
 29     for(c=getchar();c>'9'||c<'0';c=getchar())if(c=='-')f=-1;
 30     while(c>='0'&&c<='9')s=s*10+(c^'0'),c=getchar();
 31     return s*f;
 32 }
 33 Iv print(int x){
 34     if(x<0)putchar('-'),x=-x;
 35     if(x>9)print(x/10);
 36     putchar(x%10^'0');
 37 }
 38 int w[N],f[N][26];
 39 vector<int>V[N];
 40 //bitset<N>vis;
 41 int ans=1;
 42 Iv dfs(int u){
 43     //vis[u]=1;
 44     for(vector<int>::iterator v=V[u].begin();v!=V[u].end();++v){
 45             R(col,0,25)
 46                 f[*v][col]+=f[u][col];
 47             dfs(*v);
 48         }
 49     Cmax(ans,f[u][w[u]]);
 50 }
 51 char s[N];
 52 #define ON_JUDGE
 53 int main(){
 54 #ifdef ON_JUDGE
 55     freopen("path.in","r",stdin),freopen("path.out","w",stdout);
 56 #endif
 57     int n=read(),m=read();
 58     if(n<=500){
 59         scanf("%s",s+1);
 60         R(i,1,n)
 61             w[i]=(s[i]^'a');
 62         R(i,1,m){
 63             int u=read(),v=read();
 64             V[u].push_back(v);
 65         }
 66         R(i,1,n)
 67             {
 68                 R(j,1,n){
 69                     R(col,0,25)
 70                         f[j][col]=0;
 71                     f[j][w[j]]=1;
 72                 }
 73                 dfs(i);
 74             }
 75         print(ans);    
 76     }
 77     else
 78         printf("-1");
 79     return 0;
 80 }
 81 /*
 82 5 4
 83 abaca
 84 1 2
 85 1 3
 86 3 4
 87 4 5
 88 
 89 5 4
 90 abacc
 91 1 2
 92 1 3
 93 3 4
 94 4 5
 95 
 96 6 5
 97 abcdcc
 98 1 2
 99 1 3
100 3 4
101 4 5
102 5 6
103 
104 7 6
105 abacaaa
106 1 2
107 1 3
108 3 4
109 4 5
110 5 6
111 6 7
112 
113 8 8
114 acacacaa
115 2 1
116 1 4
117 3 1
118 5 3
119 6 5
120 6 4
121 3 7
122 7 8
123 */ 
path_My_CreatOnContest.cpp
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<vector>
 7 #define R(a,b,c) for(register int (a)=(b);(a)<=(c);++(a))
 8 #define nR(a,b,c) for(register int (a)=(b);(a)>=(c);--(a))
 9 #define Ii inline int
10 #define Iv inline void
11 #define Il inline long long
12 #define Ib inline bool
13 #define INF 0x7ffffff
14 #define re register
15 #define ll long long
16 #define Max(a,b) ((a)>(b)?(a):(b))
17 #define Min(a,b) ((a)<(b)?(a):(b))
18 #define Cmin(a,b) ((a)=(a)<(b)?(a):(b))
19 #define Cmax(a,b) ((a)=(a)>(b)?(a):(b))
20 #define Fill(a,b) memset((a),(b),sizeof((a)))
21 #define D_e_Line printf("\n-------------\n");
22 #define D_e(x) printf("\n______%d_______\n",x)
23 #define Pause system("pause")
24 using namespace std;
25 const int N=1000005;
26 Ii read(){
27     int s=0,f=1;char c;
28     for(c=getchar();c>'9'||c<'0';c=getchar())if(c=='-')f=-1;
29     while(c>='0'&&c<='9')s=s*10+(c^'0'),c=getchar();
30     return s*f;
31 }
32 Iv print(ll x){
33     if(x<0)putchar('-'),x=-x;
34     if(x>9)print(x/10);
35     putchar(x%10^'0');
36 }
37 //#define ON_JUDGE
38 struct Question{
39     int l,r,w;
40     void Init(){l=read(),r=read(),w=read();}
41 };
42 int fa[N],ans[N];
43 vector<Question>V;
44 Ii Find(int x){
45     return x==fa[x]?x:fa[x]=Find(fa[x]);
46 }
47 Iv Union(int x,int y){
48     x=Find(x),y=Find(y);
49     if(x!=y)
50         fa[x]=y;
51 }
52 int n;
53 Iv Paint(int x,int w){
54     ans[x]=w;
55     if(x!=1&&ans[x-1])Union(x-1,x);
56     if(x!=n&&ans[x+1])Union(x,x+1);
57 }
58 #define ON_JUDGE
59 int main(){
60 #ifdef ON_JUDGE
61     freopen("paint.in","r",stdin),freopen("paint.out","w",stdout);
62 #endif
63     n=read();
64     int m=read();
65     R(i,1,m){
66         Question ques;
67         ques.Init(),
68         V.push_back(ques);
69         //V.push_back((Question){read(),read(),read()});
70     }
71     R(i,1,n)fa[i]=i;
72     //for(vector<int>::iterator it=V.rbegin();it!=V.rend();++it){
73     nR(i,m-1,0){
74         int x=V[i].l;
75         while(x<=V[i].r){
76             if(!ans[x])
77                 Paint(x,V[i].w) ;
78             x=Find(x)+1;
79         }
80     }
81     R(i,1,n)
82         printf("%d ",ans[i]);
83     return 0;
84 }
85 /*
86 4 2
87 1 2 4
88 2 4 1
89 */
paint_AC.cpp

Conclution:

  T1:一眼LIS,两分钟写bug半小时改bug顺利A掉

  T2:先跳过,后来想出方程,但因为太怂,担心理解错误劳而无功顾全大局而搞了个随机数,溜了.……

  T3:em 可以搞定50分,先让我敲个20分暴力。。。(一个半小时的光阴似乎确凿是去了罢)……

  T4:haha,区间,线段树就行了!,,,Wait! 线段树?不是说好DP专场吗?(虽然标程是并查集*_*?),方程无果,线段树也悲伤,带上40分奇迹溜了罢

最终:

  100+0+10+40=150

  排名还是龟速单调不下降,单比Day1不知不觉已上涨十几名了

 

猜你喜欢

转载自www.cnblogs.com/bingoyes/p/10324796.html