codeforces round #424 div2
A 暴力查询,分三段查就可以了
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n, pos;
int a[N];
int main()
{
scanf("%d", &n);
for(int i = ; i <= n; ++i) scanf("%d", &a[i]);
pos = -;
for(int i = ; i <= n; ++i) if(a[i] - a[i - ] <= )
{
pos = i;
break;
}
if(pos == -)
{
puts("YES");
return ;
}
for(int i = pos; i <= n; ++i)
{
pos = ;
if(a[i] - a[i - ] > )
{
puts("NO");
return ;
}
else if(a[i] - a[i - ] < )
{
pos = i;
break;
}
}
if(!pos)
{
puts("YES");
return ;
}
for(int i = pos; i <= n; ++i)
{
if(a[i] - a[i - ] >= )
{
puts("NO");
return ;
}
}
puts("YES");
return ;
}
B 开个数组映射一下
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n;
char s1[N], s2[N], s[N];
int Map[N];
int main()
{
scanf("%s%s%s", s1 + , s2 + , s + );
n = strlen(s1 + );
for(int i = ; i <= n; ++i) Map[s1[i] - 'a'] = s2[i] - 'a';
for(int i = ; i <= strlen(s + ); ++i)
{
if(isdigit(s[i]))
printf("%c", s[i]);
if(islower(s[i]))
printf("%c", (char)(Map[s[i] - 'a'] + 'a'));
if(isupper(s[i]))
printf("%c", (char)(Map[s[i] - 'A'] + 'A'));
}
return ;
}
C 没想出来,这种题目发现用b在a上算不行就应该转换用a在b上算。统计每个b对于每个a产生的初始值,如果一个初始值出现了k次,那么就是可以的。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = ;
ll tot;
int n, k, ans;
ll a[N];
map<ll, int> mp;
vector<ll> v;
inline int read()
{
int x = , f = ; char c = getchar();
while(c < '' || c > '') { if(c == '-') f = -; c = getchar(); }
while(c >= '' && c <= '') { x = x * + c - ''; c = getchar(); }
return x * f;
}
int main()
{
scanf("%d%d", &n, &k);
for(int i = ; i <= n; ++i)
{
a[i] = read() + a[i - ];
v.push_back(a[i]);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for(register int i = ; i <= k; ++i)
{
int x;
x = read();
for(int j = ; j < v.size(); ++j)
++mp[x - v[j]];
}
for(map<ll, int> :: iterator it = mp.begin(); it != mp.end(); ++it)
ans += (it -> second == k);
printf("%d\n", ans);
return ;
}
D dp,dp[i][j]表示第i个人选到第j个钥匙,dp[i][j]=min(dp[i][j-1],max(dp[i-1][j-1],abs(a[i]-b[j])+(b[j]-p))就好了
看错题目+C题 这道题1小时35分才出来。。。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = ;
int n, k, p;
int a[N], b[N];
ll dp[N][N];
int main()
{
scanf("%d%d%d", &n, &k, &p);
for(int i = ; i <= n; ++i) scanf("%d", &a[i]);
for(int i = ; i <= k; ++i) scanf("%d", &b[i]);
sort(a + , a + n + );
sort(b + , b + k + );
for(int i = ; i <= n; ++i) dp[i][]= 1e16;
for(int i = ; i <= n; ++i)
for(int j = ; j <= k; ++j)
dp[i][j] = min(dp[i][j - ], max(dp[i - ][j - ], (ll)abs(a[i] - b[j]) + (ll)abs(b[j] - p)));
ll ans = 1e16;
for(int i = n; i <= k; ++i)
ans = min(ans, dp[n][i]);
printf("%lld\n", ans);
return ;
}
E 平衡树练习题 其实很简单就能搞定。我们发现如果选了一轮序列就会恢复原来的样子,只是删除了一些数。那么我们开set记录每个数出现的位置,从最小的数开始枚举,如果没到结尾加上上次到这次的距离,否则回到开头,因为每个数只删除一次,我们用size记录需要加上的答案,每删除一次size减1,到了一轮结束加上size。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = ;
int n, sz;
ll ans;
int a[N], tree[N];
set<int> s[N];
int main()
{
scanf("%d", &n);
for(int i = ; i <= n; ++i)
{
scanf("%d", &a[i]);
s[a[i]].insert(i);
}
sort(a + , a + n + );
int last = ;
ans = n;
sz = n;
for(int i = ; i <= n; ++i)
{
set<int> :: iterator it = s[a[i]].lower_bound(last);
if(it == s[a[i]].end())
{
ans += sz;
it = s[a[i]].begin();
}
last = *it;
--sz;
s[a[i]].erase(it);
}
printf("%lld\n", ans);
return ;
}
codeforces round #424 div2的更多相关文章
- Codeforces Round #424 Div2 E. Cards Sorting
我只能说真的看不懂题解的做法 我的做法就是线段树维护,毕竟每个数的顺序不变嘛 那么单点维护 区间剩余卡片和最小值 每次知道最小值之后,怎么知道需要修改的位置呢 直接从每种数维护的set找到现在需要修改 ...
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- Codeforces Round #359 div2
Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...
随机推荐
- 【转载】HTTP 响应头与状态码
原文地址:https://segmentfault.com/a/1190000006689786 HTTP Response Header 响应头域允许服务器传递不能放在状态行的附加信息,这些域主要描 ...
- Python开发工具搭建-Pycharm
PyCharm2017. 3.X专业版 安装使用. 注册码激活 本文以 Windows系统 为例: 1.开发工具获取及下载 Anaconda(Python 的集成工具 ) 下载地址: https:// ...
- view.getParent()与view.getRootView()
顾名思义,getParent就是获取view的父亲节点,而getRootView是寻找当前的view层次中处在最顶层的view,可理解为找出该view实例所在的view层次的根view. 如果这个vi ...
- CAD通过扩展记录实体向数据库读写用户自定义的全局数据(com接口VB语言)
VB代码实现如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ...
- Bootstrap练习:可折叠下拉菜单
代码: <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UT ...
- 00.不规则json序列化使用eval、demjson
有下面一段字符串 import json str0 = '[{"name":"白云大道营业厅","siteaddr":"x...& ...
- odoo 权限杂记
最近做一个任务督办模块,涉及到一些权限问题,折磨了几天,终于是解决了. 任务表中关联了hr_employee,分别有默认字段创建人,Many2one的发布人.监督人和Many2many类型的主责人,这 ...
- PAT 1103 Integer Factorization
The K-P factorization of a positive integer N is to write N as the sum of the P-th power of K positi ...
- Vue项目搭建及原理四
四.Vue-cli工作原理及Vue实例创建,工作原理 (一)Vue-cli原理 1.webpack其实使用了node.js的express网页服务器来进行处理网页相关的数据,相当于使用一个类似apac ...
- Java 注解之总结
注解是Spring和Mybatis框架所大量使用的技术,要想掌握框架相关技术,注解是必须要掌握的. 掌握注解的优势: 1.能够读懂别人写的代码,特别是框架相关的代码. 2.本来可能需要很多配置文件,需 ...