2017 CCPC 女生专场(重现)
2017-05-07 20:57
323 查看
链接:http://acm.hdu.edu.cn/contests/contest_show.php?cid=772
既然不能女装参赛,那么只好在HDU上被各路大佬虐杀了。。
A. Automatic Judge
上来用char接了一发,发现判断字符串相等还是string好用,又推了重敲。。总结:多想几秒再敲,手速反而会快
B. Building Shops
队友刚开始想了个递推,钦定了上次选好的最优位置的糖果店可以递推给下次用,结果WA了2个小时没找出来,后来提出这个递推是不是不科学,糖果店的位置应该每次暴力扫一遍前面的所有位置,然后比较出最小的花费。需要注意的是,题目没有说给出的教室位置是按顺序的,所以需要先排序。最后三小时多才过。。全场最坑。。。
C. Coprime Sequence
用一个数组A保存从第1个数到第 i 个数的GCD,再用一个数组B保存最后一个数到第 i 个数的GCD。遍历缺省数字的位置,取缺省位置前(A中)的GCD和缺省位置后(B 中)的GCD,再求GCD,最后取最大值即可。
D. Deleting Edges
比赛的时候以为很难没有认真想。。,赛后一看发现真的水(人呐,都不可预料。。)。因为要保持最短路不变,那么我们最后就留下最短路这条路径(同时也满足一颗树的要求)。那么这道题就变成了统计最短路的数量了,最短路算法搞一下就过去了。( 哇,为什么我早几个小时不这样想呢?
E. Easy Summation
因为数据很小,所以预处理出所有的 ik,i∈[1,10000],k∈[0,5] , 每次求和即可。
F. Forgiveness
不会 T_T(待补)
G. Graph Theory
刚开始一看以为是二分图匹配,莽交了一发(O(VE)=O(n3) 的复杂度也是敢交),果真T飞了。然后心生一计,觉得这是个贪心:把点分为2类,一类是选择建边的,一类是选择不建边的。从后往前走,记录2类点的数量。当我们碰到一个第二类点的话,那么只有后面的点可能和它连上,所以第一类点数量减1(如果已经为0则说明不满足)。走完后,剩下的第一类点构成一个完全图,可以随便连。
H. Happy Necklace
推出来 ai=ai−1+ai−3,然后莽一个矩阵快速幂即可。
I. Innumerable Ancestors
不会 T_T(待补)
J. Judicious Strategy
不会 T_T(待补)
以下是渣代码:
A:
B:
C:
D:
E:
G:
H:
既然不能女装参赛,那么只好在HDU上被各路大佬虐杀了。。
A. Automatic Judge
上来用char接了一发,发现判断字符串相等还是string好用,又推了重敲。。总结:多想几秒再敲,手速反而会快
B. Building Shops
队友刚开始想了个递推,钦定了上次选好的最优位置的糖果店可以递推给下次用,结果WA了2个小时没找出来,后来提出这个递推是不是不科学,糖果店的位置应该每次暴力扫一遍前面的所有位置,然后比较出最小的花费。需要注意的是,题目没有说给出的教室位置是按顺序的,所以需要先排序。最后三小时多才过。。全场最坑。。。
C. Coprime Sequence
用一个数组A保存从第1个数到第 i 个数的GCD,再用一个数组B保存最后一个数到第 i 个数的GCD。遍历缺省数字的位置,取缺省位置前(A中)的GCD和缺省位置后(B 中)的GCD,再求GCD,最后取最大值即可。
D. Deleting Edges
比赛的时候以为很难没有认真想。。,赛后一看发现真的水(人呐,都不可预料。。)。因为要保持最短路不变,那么我们最后就留下最短路这条路径(同时也满足一颗树的要求)。那么这道题就变成了统计最短路的数量了,最短路算法搞一下就过去了。( 哇,为什么我早几个小时不这样想呢?
E. Easy Summation
因为数据很小,所以预处理出所有的 ik,i∈[1,10000],k∈[0,5] , 每次求和即可。
F. Forgiveness
不会 T_T(待补)
G. Graph Theory
刚开始一看以为是二分图匹配,莽交了一发(O(VE)=O(n3) 的复杂度也是敢交),果真T飞了。然后心生一计,觉得这是个贪心:把点分为2类,一类是选择建边的,一类是选择不建边的。从后往前走,记录2类点的数量。当我们碰到一个第二类点的话,那么只有后面的点可能和它连上,所以第一类点数量减1(如果已经为0则说明不满足)。走完后,剩下的第一类点构成一个完全图,可以随便连。
H. Happy Necklace
推出来 ai=ai−1+ai−3,然后莽一个矩阵快速幂即可。
I. Innumerable Ancestors
不会 T_T(待补)
J. Judicious Strategy
不会 T_T(待补)
以下是渣代码:
A:
/************************************************************************* > File Name: test.cpp > Author: Akira > Mail: qaq.febr2.qaq@gmail.com ************************************************************************/ #include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <algorithm> #include <bitset> #include <queue> #include <stack> #include <map> #include <cmath> #include <vector> #include <set> #include <list> #include <ctime> #include <climits> typedef long long LL; typedef unsigned long long ULL; typedef long double LD; #define MST(a,b) memset(a,b,sizeof(a)) #define CLR(a) MST(a,0) #define Sqr(a) ((a)*(a)) using namespace std; #define MaxN 100001 #define MaxM MaxN*10 #define INF 0x3f3f3f3f #define PI 3.1415926535897932384626 const int mod = 1E9+7; const double eps = 1e-6; #define bug cout<<88888888<<endl; #define debug(x) cout << #x" = " << x << endl; int T; int n, m; int pro[15]; string times, sta; int main() { cin >> T; while(T--) { CLR(pro); int ans = 0, total = 0; cin >> n >> m; int xuhao; while(m--) { cin >> xuhao >> times >> sta; xuhao -= 1000; if(pro[xuhao]==-1) continue; if(sta=="AC") { int cnt = (times[1]-'0')*60 + (times[3]-'0')*10+(times[4]-'0'); pro[xuhao] += cnt; total += pro[xuhao]; ans++; pro[xuhao] = -1; } else { pro[xuhao] += 20; } } cout << ans << " " << total << endl; } }
B:
/************************************************************************* > File Name: test.cpp > Author: Akira > Mail: qaq.febr2.qaq@gmail.com ************************************************************************/ #include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <algorithm> #include <bitset> #include <queue> #include <stack> #include <map> #include <cmath> #include <vector> #include <set> #include <list> #include <ctime> #include <climits> typedef long long LL; typedef unsigned long long ULL; typedef long double LD; #define MST(a,b) memset(a,b,sizeof(a)) #define CLR(a) MST(a,0) #define Sqr(a) ((a)*(a)) using namespace std; #define MaxN 100001 #define MaxM MaxN*10 #define INF 0x3f3f3f3f #define PI 3.1415926535897932384626 const int mod = 1E9+7; const double eps = 1e-6; #define bug cout<<88888888<<endl; #define debug(x) cout << #x" = " << x << endl; int n; struct Node { LL d, c; bool operator<(Node &a) const { return d<a.d; } }node[MaxN]; LL DP[MaxN][2]; void solve() { DP[1][1] = node[1].c; DP[1][0] = 2*INF; for(int i=2;i<=n;i++) { LL all=node[i].d-node[i-1].d; // cout<<all<<endl; DP[i][1] = min(DP[i-1][1], DP[i-1][0])+node[i].c; DP[i][0] = DP[i-1][1] + node[i].d - node[i-1].d; for(int j=i-1;j>1;j--) { all+=(node[j].d-node[j-1].d)*(i-j+1); //cout<< all << " " << DP[j][1] << endl; DP[i][0] = min(DP[i][0], DP[j-1][1]+all); } } //for(int i=1;i<=n;i++) cout << DP[i][1] << ' ' << DP[i][0] << endl; LL ans = min(DP [0], DP [1]); printf("%lld\n", ans); } int main() { node[0].d = -2*INF; while(~scanf("%d", &n)) { for(int i=1;i<=n;i++) scanf("%lld%lld", &node[i].d, &node[i].c); sort(node+1, node+1+n); solve(); } }
C:
/************************************************************************* > File Name: test.cpp > Author: Akira > Mail: qaq.febr2.qaq@gmail.com ************************************************************************/ #include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <algorithm> #include <bitset> #include <queue> #include <stack> #include <map> #include <cmath> #include <vector> #include <set> #include <list> #include <ctime> #include <climits> typedef long long LL; typedef unsigned long long ULL; typedef long double LD; #define MST(a,b) memset(a,b,sizeof(a)) #define CLR(a) MST(a,0) #define Sqr(a) ((a)*(a)) using namespace std; #define MaxN 100001 #define MaxM MaxN*10 #define INF 0x3f3f3f3f #define PI 3.1415926535897932384626 const int mod = 1E9+7; const double eps = 1e-6; #define bug cout<<88888888<<endl; #define debug(x) cout << #x" = " << x << endl; int T; int n; int A[MaxN], B[MaxN], C[MaxN]; int gcd(int a, int b) { return b==0?a:gcd(b,a%b); } void solve() { int ans = 0; for(int i=1;i<=n-2;i++) { ans = max(ans, gcd(B[i], C[n-i-1])); } ans = max(ans, B[n-1]); ans = max(ans, C[n-1]); printf("%d\n", ans); } int main() { scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i=1;i<=n;i++) scanf("%d", &A[i]); B[1] = A[1]; for(int i=2;i<=n;i++) { B[i] = gcd(B[i-1],A[i]); } C[1] = A ; for(int i=2;i<=n;i++) { C[i] = gcd(C[i-1], A[n-i+1]); } solve(); } }
D:
/************************************************************************* > File Name: test.cpp > Author: Akira > Mail: qaq.febr2.qaq@gmail.com ************************************************************************/ #include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <algorithm> #include <bitset> #include <queue> #include <stack> #include <map> #include <cmath> #include <vector> #include <set> #include <list> #include <ctime> #include <climits> typedef long long LL; typedef unsigned long long ULL; typedef long double LD; #define MST(a,b) memset(a,b,sizeof(a)) #define CLR(a) MST(a,0) #define Sqr(a) ((a)*(a)) using namespace std; #define MaxN 100001 #define MaxM MaxN*10 #define INF 0x3f3f3f3f #define PI 3.1415926535897932384626 const int mod = 1E9+7; const double eps = 1e-6; #define bug cout<<88888888<<endl; #define debug(x) cout << #x" = " << x << endl; int n; char str[55][55]; int MAP[55][55]; int value[55]; int dis[55]; int vis[55]; typedef pair<int,int> pii; struct cmp { bool operator()(pii a, pii b) { return a.first>b.first; } }; void Dijkstra() { CLR(value); CLR(vis); for(int i=0;i<n;i++) dis[i] = INF; dis[0] = 0; priority_queue<pii, vector<pii>, cmp> Q; Q.push(make_pair(0,0)); while(!Q.empty()) { pii tmp = Q.top(); Q.pop(); int u = tmp.second; if(vis[u]) continue; vis[u] = 1; for(int v=1;v<n;v++) { if(MAP[u][v]==0 || v==u) continue; if( dis[v] > tmp.first + MAP[u][v]) { dis[v] = tmp.first + MAP[u][v]; Q.push(make_pair(dis[v], v)); value[v] = 1; } else if(dis[v] == tmp.first + MAP[u][v]) { value[v] ++; } } } } void solve() { Dijkstra(); LL ans = 1; if( dis[n-1] == INF ) ans = 0; else { for(int i=1;i<n;i++) { ans*=value[i]; if(ans>mod) ans%=mod; } } printf("%lld\n", ans); } int main() { while(~scanf("%d", &n)) { for(int i=0;i<n;i++) { scanf("%s", &str[i]); } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { MAP[i][j] = str[i][j] - '0'; //cout << i << "-" << j <<":" << MAP[i][j] <<endl; } } solve(); } }
E:
/************************************************************************* > File Name: test.cpp > Author: Akira > Mail: qaq.febr2.qaq@gmail.com ************************************************************************/ #include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <algorithm> #include <bitset> #include <queue> #include <stack> #include <map> #include <cmath> #include <vector> #include <set> #include <list> #include <ctime> #include <climits> typedef long long LL; typedef unsigned long long ULL; typedef long double LD; #define MST(a,b) memset(a,b,sizeof(a)) #define CLR(a) MST(a,0) #define Sqr(a) ((a)*(a)) using namespace std; #define MaxN 100001 #define MaxM MaxN*10 #define INF 0x3f3f3f3f #define PI 3.1415926535897932384626 const int mod = 1E9+7; const double eps = 1e-6; #define bug cout<<88888888<<endl; #define debug(x) cout << #x" = " << x << endl;; int T; int n,k; int F[10010][6]; int main() { scanf("%d", &T); for(int i=1;i<=10000;i++) { for(int j=0;j<=5;j++) { LL cnt = 1; for(int l=1;l<=j;l++) { cnt*=i; if(cnt>mod) cnt%=mod; } F[i][j] = cnt; } } while(T--) { scanf("%d%d", &n, &k); int sum = 0; for(int i=1;i<=n;i++) { sum += F[i][k]; if(sum>mod) sum%=mod; } printf("%d\n", sum); } }
G:
/************************************************************************* > File Name: test.cpp > Author: Akira > Mail: qaq.febr2.qaq@gmail.com ************************************************************************/ #include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <algorithm> #include <bitset> #include <queue> #include <stack> #include <map> #include <cmath> #include <vector> #include <set> #include <list> #include <ctime> #include <climits> typedef long long LL; typedef unsigned long long ULL; typedef long double LD; #define MST(a,b) memset(a,b,sizeof(a)) #define CLR(a) MST(a,0) #define Sqr(a) ((a)*(a)) using namespace std; #define MaxN 100001 #define MaxM MaxN*10 #define INF 0x3f3f3f3f #define PI 3.1415926535897932384626 const int mod = 1E9+7; const double eps = 1e-6; #define bug cout<<88888888<<endl; #define debug(x) cout << #x" = " << x << endl; int T,n; int A[MaxN]; bool judge() { int use = 0; for(int i=n;i>=2;i--) { if(A[i]==1) use++; else { if(use==0) return false; else { use--; } } } return true; } void solve() { if(judge()) puts("Yes"); else puts("No"); } int main() { scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i=2;i<=n;i++) scanf("%d", &A[i]); if( n&1 || A ==2) puts("No"); else solve(); } }
H:
/************************************************************************* > File Name: test.cpp > Author: Akira > Mail: qaq.febr2.qaq@gmail.com ************************************************************************/ #include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <algorithm> #include <bitset> #include <queue> #include <stack> #include <map> #include <cmath> #include <vector> #include <set> #include <list> #include <ctime> #include <climits> typedef long long LL; typedef unsigned long long ULL; typedef long double LD; #define MST(a,b) memset(a,b,sizeof(a)) #define CLR(a) MST(a,0) #define Sqr(a) ((a)*(a)) using namespace std; #define MaxN 100001 #define MaxM MaxN*10 #define INF 0x3f3f3f3f #define PI 3.1415926535897932384626 const int mod = 1E9+7; const double eps = 1e-6; #define bug cout<<88888888<<endl; #define debug(x) cout << #x" = " << x << endl; const int MatLen = 3; int T; LL n; struct Mat { LL mat[MatLen][MatLen]; Mat() { CLR(mat); } void init(LL v) { for(int i=0;i<=MatLen;++i) mat[i][i] = v; } }; Mat operator * (Mat a, Mat b) { Mat c; for(int k=0;k<MatLen;k++) { for(int i=0;i<MatLen;i++) { for(int j=0;j<MatLen;j++) { c.mat[i][j] += a.mat[i][k]%mod * b.mat[k][j]%mod; } } } return c; } Mat operator^(Mat a, LL k) { Mat c; for(int i=0;i<MatLen;i++) { for(int j=0;j<MatLen;j++) { c.mat[i][j] = (i==j); } } for(;k;k>>=1) { if(k&1) c = c*a; a = a*a; } return c; } int main() { scanf("%d", &T); while(T--) { scanf("%lld", &n); if(n==2) puts("3"); else if (n==3) puts("4"); else if(n==4) puts("6"); else { Mat num; num.mat[0][0] = 1; num.mat[0][1] = 0; num.mat[0][2] = 1; num.mat[1][0] = 1; num.mat[1][1] = 0; num.mat[1][2] = 0; num.mat[2][0] = 0; num.mat[2][1] = 1; num.mat[2][2] = 0; Mat ans = num^(n-4); LL ANS = (ans.mat[0][0]*6 + ans.mat[0][1]*4 + ans.mat[0][2]*3) % mod; printf("%lld\n", ANS); } } }
相关文章推荐
- 2017中国大学生程序设计竞赛 - 女生专场(重现)
- 第二届CCPC女生赛 粗略题解(要做重现的不要看哦)
- "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场(重现) HDU 5702
- HDU6024 Building Shops 2017中国大学生程序设计竞赛 - 女生专场
- "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场(重现) HDU 5703
- "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场(重现) HDU 5704
- "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场(重现) HDU 5705
- "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场(重现) HDU 5706
- 2017CCPC女生赛 hdu 6030 Happy Necklace
- 2017CCPC女生赛 hdu 6031 Innumerable Ancestors
- "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场(重现) HDU 5707
- HDU6027 Easy Summation 2017中国大学生程序设计竞赛 - 女生专场
- 2017中国大学生程序设计竞赛 - 女生专场
- 2017中国大学生程序设计竞赛 - 女生专场 1001
- "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场(重现)解题思路
- HDU-5702-Solving Order【2016CCPC女生专场】
- 2017中国大学生程序设计竞赛 - 女生专场
- HDU-5703-Desert【2016CCPC女生专场】
- "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场(重现)解题思路
- HDU-5706-GirlCat【BFS】【2016CCPC女生专场】