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. Java_Web三大框架之Hibernate+HQL语言基础

    12.1 HQL语言基础Hibernate查询语言为HQL(Hibernate Query Language),可以直接使用实体类名及属性.HQL语法类似于SQL,有SQL的关键词如select.fr ...

  2. mysql命令行导出数据

    1. 包含表头 mysql -h${1} -P${2} -u${3} -p${4} -Dpom_${5} --default-character-set=utf8 -B -e > result. ...

  3. python web 开发学习路线

    转载,备着 自己目前学习python web 开发, 经过两个月的摸索,目前对web开发有了浅显的认识,把自己的学习过程贴出来.1.python入门推荐老齐<从零开始学python>,&l ...

  4. Oracle 函数总结

    <1>=========================返回 String,其中包含有与指定的字符代码相关的字符======================== 函      数:< ...

  5. ARX自定义实体

    本文介绍了构造自定义实体的步骤.必须继承的函数和必须注意的事项 1.新建一个从AcDbEntity继承的类,如EntTest,必须添加的头文件: "stdarx.h"," ...

  6. S3C2440中断

    韦东山老师一期中断课程学习: 总结: 程序启动后工作流程,程序从0地址开始执行Reset  --> 重定位  -->ldr pc,=main [绝对跳转到SDRAM中执行main()函数] ...

  7. form:input 标签使用

    <form:input path="suplier" htmlEscape="false" maxlength="50" id=&qu ...

  8. C# 泛基

    1 你有时候希望在父类规定一些行为,让子类无法修改,但是这些实现是依赖一个子类才能获取的值,你又不可能知道所有的子类 ,没办法替它在父类里面初始化,这时候就需要在父类里面定义一个每个子类一个的,但又是 ...

  9. 棋盘DP三连——洛谷 P1004 方格取数 &&洛谷 P1006 传纸条 &&Codevs 2853 方格游戏

    P1004 方格取数 题目描述 设有N $\times N$N×N的方格图(N $\le 9$)(N≤9),我们将其中的某些方格中填入正整数,而其他的方格中则放入数字00.如下图所示(见样例): A ...

  10. Centos 7中,防火墙配置端口规则

    注意:firewalld服务有两份规则策略配置记录,配置永久生效的策略记录时,需要执行"reload"参数后才能立即生效: Permanent:永久生效的 RunTime:现在正在 ...