The 15th Zhejiang Provincial Collegiate Programming Contest(部分题解)
题意
给出n和n个数,判断该数列是否是凸形的。
解题思路
从前往后第一对逆序数,和从后往前第一队逆序数,如果都非零而且相邻,证明该数组是凸形的。
代码
#include <cstdio>
const int maxn = + ;
int a[maxn]; int main()
{
int T;
scanf("%d", &T);
while(T--) {
int n;
scanf("%d", &n);
for(int i = ; i < n; i++) {
scanf("%d", &a[i]);
}
int q = , h = , i;
for(i = ; i < n - ; i++) {
if(a[i] < a[i + ])
q++;
else
break;
}
for(; i < n - ; i++) {
if(a[i] > a[i + ])
h++;
else
break;
}
//printf("%d %d\n", q, h); if(q && h && q + h == n - )
puts("Yes");
else
puts("No");
}
return ;
}
题意
给出n,然后给出两个长度为n的序列S 和 D,问给每个D加上一个数k(可正,可负,可零),最大的耦合度是多少
解题思路
先用S减D得到每个差值的次数,然后找到差值次数最多的数即可。
代码
#include <cstdio>
#include <map> using namespace std;
const int maxn = + ;
int D[maxn], S[maxn];
int n; map<int, int> mp;
int main()
{
int T;
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i = ; i < n; i++) {
scanf("%d", &D[i]);
}
for(int i = ; i < n; i++) {
scanf("%d", &S[i]);
} mp.clear();
for(int i = ; i < n; i++) {
mp[S[i] - D[i]]++;
}
int maxc = ;
map<int, int>::iterator it;
for(it = mp.begin(); it != mp.end(); it++) {
if((*it).second > maxc)
maxc = (*it).second;
}
printf("%d\n", maxc);
}
return ;
}
给出n和k,然后n个数,只要有一个数加上k能够将7整除,就是Yes。
#include <cstdio> int n, k;
int main()
{
int T;
scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &k);
int a, f = ;
for(int i = ; i < n; i++) {
scanf("%d", &a);
if((a + k) % == )
f = ;
}
if(f)
puts("Yes");
else
puts("No");
}
return ;
}
ZOJ 4035 Doki Doki Literature Club
给出n个单词列表和单词限制数m,然后每个单词的满足度,问组成m个最大满意度的单词列表。
排序,注意先按满意度排,再按照字典序排,另外可能超int范围。
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
const int wl = + ;
const int maxw = + ;
struct Word {
char w[wl];
int s;
bool operator < (const struct Word &a) const {
if(a.s == s) {
if(strcmp(a.w, w) > )
return ;
else
return ;
}
return a.s < s;
}
}wo[maxw]; int n, m;
int main()
{
int T;
scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) {
scanf("%s %d", wo[i].w, &wo[i].s);
} sort(wo + , wo + n + );
/*for(int i = 1; i <= n; i++) {
printf("%s %d\n", wo[i].w, wo[i].s);
}*/
long long sc = ;
for(int i = ; i <= m; i++) {
sc += (long long)(m - i + ) * wo[i].s;
}
printf("%lld",sc);
for(int i = ; i <= m; i++) {
printf(" %s", wo[i].w);
}
puts("");
}
return ;
}
The 15th Zhejiang Provincial Collegiate Programming Contest(部分题解)的更多相关文章
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - L Doki Doki Literature Club
Doki Doki Literature Club Time Limit: 1 Second Memory Limit: 65536 KB Doki Doki Literature Club ...
- 2018浙江省赛(ACM) The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple
我是铁牌选手 这次比赛非常得爆炸,可以说体验极差,是这辈子自己最脑残的事情之一. 天时,地利,人和一样没有,而且自己早早地就想好了甩锅的套路. 按理说不开K就不会这么惨了啊,而且自己也是毒,不知道段错 ...
- 【贪心】LIS @The 15th Zhejiang Provincial Collegiate Programming Contest E
传送门 题意要你构造一个序列,使得该序列的每个位置上的最长上升子序列的长度能构成给定的序列. 构造序列的元素要求还要求满足给定的上下界 solution 我们可以把给出的最长上升子序列的长度按升序排列 ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - M Lucky 7
Lucky 7 Time Limit: 1 Second Memory Limit: 65536 KB BaoBao has just found a positive integer se ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - J CONTINUE...?
CONTINUE...? Time Limit: 1 Second Memory Limit: 65536 KB Special Judge DreamGrid has clas ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - B King of Karaoke
King of Karaoke Time Limit: 1 Second Memory Limit: 65536 KB It's Karaoke time! DreamGrid is per ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple -A Peak
Peak Time Limit: 1 Second Memory Limit: 65536 KB A sequence of integers is called a peak, if ...
- ZOJ 4033 CONTINUE...?(The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple)
#include <iostream> #include <algorithm> using namespace std; ; int a[maxn]; int main(){ ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...
随机推荐
- 值得推荐的C/C++框架和库 (真的很强大)〔转〕
http://m.blog.csdn.net/article/details?id=42541419
- django 如何接收bootstrap-table传送的 ajax数组
今天在用django传递id的时候,使用 alert(ids)以及console.log("id:",ids),都可以看到是把选中的数据的id打印出来的,用console.log可 ...
- linux 解压 压缩 常见命令
压缩命令: .tar tar -cvf 文件名称.tar 文件或者文件夹 .tar.gz tar -zcvf 文件名称.tar.gz 文件或者文件夹 .tar.xz tar -Jcf 文件名称.tar ...
- Go学习之旅
备忘这个 官方文档 https://go-zh.org/doc/ Go指南 https://tour.go-zh.org/welcome/1 Go语言圣经 https://yar999.gitbook ...
- CSS3背景相关新增属性
background-clip border-box:充满边框和内边距,内容. padding-box:充满内边距,内容 content-box:只充满内容 background-origin bor ...
- Linux-3.0.8中基于S5PV210的GPIO模块代码追踪和分析
编写按键驱动时,想知道内核是如何管理GPIO的,所以开始追踪代码,中间走了一些弯路,现记录于此. 追踪代码之前,我猜测:第一,这部分代码应该在系统set up阶段执行:第二,GPIO的代码应该在mac ...
- 洛谷P1776--宝物筛选(单调队列+多重背包)
https://www.luogu.org/problemnew/show/P1776 单调队列+多重背包的讲解https://www.cnblogs.com/JoeFan/p/4165956.htm ...
- MyBatis的好处及常见问题
好处 MyBatis持久层框架,它对jdbc的操作数据库的过程进行封装,使开发者只需要关注 SQL 本身,而不需要花费精力去处理例如注册驱动.创建connection.创建statement.手动设置 ...
- python基础自学 第二天
注释 分类 单行注释 多行注释 作用 使用自己熟悉的语言,在程序中对某些代码进行标注说明,增强程序可读性 单行注释(行注释) 以 # 开头,#右边所有的东西就被当成说明文字,而不是要执行的程序,只是说 ...
- Linux 常用分区方式
1 分两个区 主目录:/ 交换分区:swap 2 常用分区方式,以使用100G空间安装linux为例 引导分区: 挂载点/boot,分区格式ext4,500M以内即可 交换分区: 无挂载点,分区格式选 ...