ZOJ 4024 Peak

题意

给出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 ;
}

ZOJ 4025 King of Karaoke

题意

给出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 ;
}

ZOJ 4036 Lucky 7

给出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(部分题解)的更多相关文章

  1. 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 ...

  2. 2018浙江省赛(ACM) The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple

    我是铁牌选手 这次比赛非常得爆炸,可以说体验极差,是这辈子自己最脑残的事情之一. 天时,地利,人和一样没有,而且自己早早地就想好了甩锅的套路. 按理说不开K就不会这么惨了啊,而且自己也是毒,不知道段错 ...

  3. 【贪心】LIS @The 15th Zhejiang Provincial Collegiate Programming Contest E

    传送门 题意要你构造一个序列,使得该序列的每个位置上的最长上升子序列的长度能构成给定的序列. 构造序列的元素要求还要求满足给定的上下界 solution 我们可以把给出的最长上升子序列的长度按升序排列 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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(){ ...

  9. 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 ...

随机推荐

  1. 第50章:Java操作MongoDB-MongoDB和Spring

    ① Spring通过Spring Data MongoDB模块来集成和支持MongoDB ②Maven加入lib包 <dependency> <groupId>org.spri ...

  2. struct,map,json 互相转换

    1.1 struct to json 准备 很简单,使用encoding包可以互相转换,没什么好说的,但是有几点注意: 1.结构体内需要序列化的字段首字母大写(遵循驼峰式命名),不需要序列化的字段小写 ...

  3. OpenAL音频库例程

    Windows下C++可用的OpenAL demo. 基于alut工具库的OpenAL例程,涵盖了基本的OpenAL指令,对部分作出了注释,并且可以播放(当然得把对应的音频文件放到正确的路径下). # ...

  4. [转]JDBC如何进行超时设置

    文档来源:https://jingyan.baidu.com/article/fc07f98922615a12ffe519ce.html 恰当的JDBC超时设置能够有效地减少服务失效的时间.本文将对数 ...

  5. opencv2.4.13+python2.7学习笔记--使用 knn对手写数字OCR

    阅读对象:熟悉knn.了解opencv和python. 1.knn理论介绍:算法学习笔记:knn理论介绍 2. opencv中knn函数 路径:opencv\sources\modules\ml\in ...

  6. svn提交出现错误 svn: Working copy 'D:\...'locked.

    更新svn内容时出现如下的错误: svn: Working copy 'D:\tools\Workspaces\EclipseForNewSTLJ\javashop\b2c\src\main\weba ...

  7. Leetcode(二)两数相加

    两数相加 题目描述 给出两个非空的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字. 如果,我们将这两个数相加起来,则会返回一个新的链 ...

  8. 个人 WPF+EF(DBFirst) 简单应用开发习惯及EF学习测试(备忘) -- 2

    接上篇:个人 WPF+EF(DBFirst) 简单应用开发习惯及EF学习测试(备忘) -- 1 Step1 在主程序中设置连接数据库 从Model类库的 App.Config 把数据库字符串拷贝出来, ...

  9. python3+redis问题求解

    学生管理系统   更新学生信息没做出来,找个大神补全下.谢谢. # 记录: # bug:操作后若退出需要两次退出才行. 待修复 # 下一步:链接redis进行使用. # 更新学生库信息 待完成 imp ...

  10. mac上terminal_问题_1117

    (1)安装Homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install ...