The 15th Zhejiang Provincial Collegiate Programming Contest(部分题解)
Posted wenzhixin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The 15th Zhejiang Provincial Collegiate Programming Contest(部分题解)相关的知识,希望对你有一定的参考价值。
题意
给出n和n个数,判断该数列是否是凸形的。
解题思路
从前往后第一对逆序数,和从后往前第一队逆序数,如果都非零而且相邻,证明该数组是凸形的。
代码
1 #include <cstdio> 2 const int maxn = 100000 + 10; 3 int a[maxn]; 4 5 int main() 6 { 7 int T; 8 scanf("%d", &T); 9 while(T--) { 10 int n; 11 scanf("%d", &n); 12 for(int i = 0; i < n; i++) { 13 scanf("%d", &a[i]); 14 } 15 int q = 0, h = 0, i; 16 for(i = 0; i < n - 1; i++) { 17 if(a[i] < a[i + 1]) 18 q++; 19 else 20 break; 21 } 22 for(; i < n - 1; i++) { 23 if(a[i] > a[i + 1]) 24 h++; 25 else 26 break; 27 } 28 //printf("%d %d ", q, h); 29 30 if(q && h && q + h == n - 1) 31 puts("Yes"); 32 else 33 puts("No"); 34 } 35 return 0; 36 }
题意
给出n,然后给出两个长度为n的序列S 和 D,问给每个D加上一个数k(可正,可负,可零),最大的耦合度是多少
解题思路
先用S减D得到每个差值的次数,然后找到差值次数最多的数即可。
代码
1 #include <cstdio> 2 #include <map> 3 4 using namespace std; 5 const int maxn = 100000 + 10; 6 int D[maxn], S[maxn]; 7 int n; 8 9 map<int, int> mp; 10 int main() 11 { 12 int T; 13 scanf("%d", &T); 14 while(T--) { 15 scanf("%d", &n); 16 for(int i = 0; i < n; i++) { 17 scanf("%d", &D[i]); 18 } 19 for(int i = 0; i < n; i++) { 20 scanf("%d", &S[i]); 21 } 22 23 mp.clear(); 24 for(int i = 0; i < n; i++) { 25 mp[S[i] - D[i]]++; 26 } 27 int maxc = 0; 28 map<int, int>::iterator it; 29 for(it = mp.begin(); it != mp.end(); it++) { 30 if((*it).second > maxc) 31 maxc = (*it).second; 32 } 33 printf("%d ", maxc); 34 } 35 return 0; 36 }
给出n和k,然后n个数,只要有一个数加上k能够将7整除,就是Yes。
1 #include <cstdio> 2 3 int n, k; 4 int main() 5 { 6 int T; 7 scanf("%d", &T); 8 while(T--) { 9 scanf("%d%d", &n, &k); 10 int a, f = 0; 11 for(int i = 0; i < n; i++) { 12 scanf("%d", &a); 13 if((a + k) % 7 == 0) 14 f = 1; 15 } 16 if(f) 17 puts("Yes"); 18 else 19 puts("No"); 20 } 21 return 0; 22 }
ZOJ 4035 Doki Doki Literature Club
给出n个单词列表和单词限制数m,然后每个单词的满足度,问组成m个最大满意度的单词列表。
排序,注意先按满意度排,再按照字典序排,另外可能超int范围。
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 using namespace std; 6 const int wl = 15 + 10; 7 const int maxw = 100 + 10; 8 struct Word { 9 char w[wl]; 10 int s; 11 bool operator < (const struct Word &a) const { 12 if(a.s == s) { 13 if(strcmp(a.w, w) > 0) 14 return 1; 15 else 16 return 0; 17 } 18 return a.s < s; 19 } 20 }wo[maxw]; 21 22 int n, m; 23 int main() 24 { 25 int T; 26 scanf("%d", &T); 27 while(T--) { 28 scanf("%d%d", &n, &m); 29 for(int i = 1; i <= n; i++) { 30 scanf("%s %d", wo[i].w, &wo[i].s); 31 } 32 33 sort(wo + 1, wo + n + 1); 34 /*for(int i = 1; i <= n; i++) { 35 printf("%s %d ", wo[i].w, wo[i].s); 36 }*/ 37 long long sc = 0; 38 for(int i = 1; i <= m; i++) { 39 sc += (long long)(m - i + 1) * wo[i].s; 40 } 41 printf("%lld",sc); 42 for(int i = 1; i <= m; i++) { 43 printf(" %s", wo[i].w); 44 } 45 puts(""); 46 } 47 return 0; 48 }
以上是关于The 15th Zhejiang Provincial Collegiate Programming Contest(部分题解)的主要内容,如果未能解决你的问题,请参考以下文章
ZJCPC2018 第15届 浙江省赛The 15th Zhejiang Provincial Collegiate Programming Contest(MABLJK 6题)
The 18th Zhejiang University Programming Contest
The 17th Zhejiang Provincial Contest B. Bin Packing Problem(线段树+map)
The 18th Zhejiang Provincial Collegiate Programming Contest 补题记录(ACFGJLM)
The 19th Zhejiang Provincial Collegiate Programming Contest F - Easy Fix(主席树)
The 19th Zhejiang Provincial Collegiate Programming Contest F - Easy Fix(主席树)