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 ...
随机推荐
- Ubuntu 16.04上安装Global阅读源代码工具
参照10年前写的文档 (Linux源码阅读工具lxr和glimpse的安装与配置),想重新搭建一个源代码阅读工具,发现源里面都没有相关的工具了. 然后看到有更简单的安装工具Global可以使用,所以果 ...
- switch_root vs pivot_root vs chroot【转】
1. pivot_root can/should be used together with chroot pivot_root new_root put_old pivot_root moves t ...
- ffmpeg源码编译安装(Compile ffmpeg with source) Part 2 : 扩展安装
在Ubuntu,Debian,Mint上编译ffmpeg 本文主要为在Ubuntu,Debian和Mint上编译安装ffmpeg和库文件以及一些扩展的编解码器.当然这与从源中安装无关. 请首先看一下通 ...
- [转] 分代垃圾回收的 新旧代引用问题(原标题:Back To Basics: Generational Garbage Collection)
原文链接: https://blogs.msdn.microsoft.com/abhinaba/2009/03/02/back-to-basics-generational-garbage-colle ...
- kafka中zookeeper的操作
bin/zookeeper-shell.sh localhost:2181 <<< "get /brokers/ids/4" ./zkCli.sh -server ...
- 谈谈一些有趣的CSS题目(十六)-- 奇妙的 background-clip: text
开本系列,谈谈一些有趣的 CSS 题目,题目类型天马行空,想到什么说什么,不仅为了拓宽一下解决问题的思路,更涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题 ...
- 【webpack】-- 自动刷新与解析
前端需要频繁的修改js和样式,且需要根据浏览器的页面效果不断的做调整:而且往往我们的开发目录和本地发布目录不是同一个,修改之后需要发布一下:另外一点就是并不是所有的效果都可以直接双击页面就能看到,我们 ...
- ZKWeb网页框架2.1正式发布
2.1.0更新的内容有 更新引用类库 NHibernate 5.1.0 Npgsql 3.2.7 MySqlConnector 0.37.0 Dapper 1.50.4 Dommel 1.10.1 Z ...
- Python编程练习:编程实现恺撒密码
问题描述:凯撒密码是古罗马凯撒大帝用来对军事情报进行加解密的算法,它采用了替换方法对信息中的每一个英文字符循环替换为字母表序列中该字符后面的第三个字符,即,字母表的对应关系如下: 原文:A B C D ...
- Android 展示控件之Surface、SurfaceView、SurfaceHolder及SurfaceHolder.Callback之间的关系
一.Surface Surface在SDK的文档中的描述是这样的:Handle onto a raw buffer that is being managed by the screen compos ...