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的更多相关文章

  1. Codeforces Round #424 Div2 E. Cards Sorting

    我只能说真的看不懂题解的做法 我的做法就是线段树维护,毕竟每个数的顺序不变嘛 那么单点维护 区间剩余卡片和最小值 每次知道最小值之后,怎么知道需要修改的位置呢 直接从每种数维护的set找到现在需要修改 ...

  2. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  3. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  4. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  5. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  6. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  7. Codeforces Round #626 Div2 D,E

    比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...

  8. CodeForces Round 192 Div2

    This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...

  9. Codeforces Round #359 div2

    Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...

随机推荐

  1. Centos 修改源

    1首先备份原来的配置文件: mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2下载对应版本r ...

  2. 【VHDL】深度讲解二进制无符号和有符号加法处理溢出的问题

    1.Unsigned adders 这个比较简单,只需在A.B前面扩展一位0防止溢出,溢出的数填到第n位cout,n-1到0位就是sum. , 2.Signed adders 一开始也搞不懂下图中为什 ...

  3. How an SSL connection is established

    An SSL connection between a client and server is set up by a handshake, the goals of which are: To s ...

  4. jq购物车结算功能

    css *{font-style: normal} .gw{margin: 8px;} .gw::after{display: block;clear: both;content: '';margin ...

  5. 51.percentiles rank以及网站访问时延SLA统计

    主要知识点: percentile_ranks的用法 percentile的优化     一.percentile_ranks的用法 SLA:就是所提供的服务的标准. 比如一个网站的提供的访问延时的S ...

  6. Python 5 运算符

    数学运算符: + 加                 1 + 1 = 2 -   减 2 - 1 = 1 ×  乘 2 × 2 = 4 /   除 3 / 2 = 1.5 不同版本可能显示小数位数不同 ...

  7. noip模拟赛 SAC E#1 - 一道中档题 Factorial

    题目背景 数据已修改 SOL君(炉石主播)和SOL菌(完美信息教室讲师)是好朋友. 题目描述 SOL君很喜欢阶乘.而SOL菌很喜欢研究进制. 这一天,SOL君跟SOL菌炫技,随口算出了n的阶乘. SO ...

  8. java web解决表单重复提交

    首先我们在讨论如何解决表单重复提交问题之前先来解决三个问题:1.什么叫表单重复提交?2.什么情况下会出现表单重复提交?3.什么情况需要避免表单重复提交? 什么叫表单提交问题,说白了,就是同一份信息,重 ...

  9. 高仿京东APP首页“京东快报”自己主动向上滚动的广告条

    转载请标明出处: http://blog.csdn.net/hai_qing_xu_kong/article/details/51013562 本文出自:[顾林海的博客] 前言 上次在京东APP上买东 ...

  10. loosejar原理简要分析

    loosejar这个小工具能够动态分析出应用中有每一个jar包的实际使用情况,详情请參阅<通过loosejar清理应用中冗余的jar包>基本原理是利用instrumentation的特性用 ...