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. Zabbix自带的mysql监控模块

    Zabbix自带的mysql监控模块 [root@Cagios zabbix-]# cp conf/zabbix_agentd/userparameter_mysql.conf /usr/local/ ...

  2. CAD绘制一个直径标注(com接口VB语言)

    主要用到函数说明: _DMxDrawX::DrawDimDiametric 绘制一个直径标注.详细说明如下: 参数 说明 DOUBLE dChordPointX 在被标注的曲线上的第一个点X值 DOU ...

  3. 可以用作javascript异步模式的函数写法

    1. 回调函数 f1(); f2(); function f1(callback) { setTimeout(function() { // f1的任务代码 callback(); }, 1000); ...

  4. tp定时任务,传参问题

    <?phpnamespace app\command; use think\console\Command;use think\console\Input;use think\console\i ...

  5. php第十四节课

    投票 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...

  6. 【解题报告】洛谷 P1231 教辅的组成

    [解题报告]洛谷 P1231 教辅的组成 题目链接 CSDN链接 这道题就只是一道普通的最大流问题,但是关键所在就是如何构图.要不是我看了题解,真的想不到这个构图方法呢 题目大意我就不写了,自己看好了 ...

  7. uva10082 WERTYU (Uva10082)

    A common typing error is to place the hands on the keyboard one row to the right of the correct posi ...

  8. LOJ 6145 Easy (动态点分治+线段树)

    题目传送门 先建出来点分树,以每个点为根开线段树,维护点分子树内编号为$[l,r]$的儿子到根的距离最小值 每次查询$x$开始,沿着点分树向上跑,在每个点的线段树的$[l,r]$区间里都查一遍取$mi ...

  9. python最好用的IDE及查看源码的方法

    一.PyCharm 很多语言都有比较流行的开发工具,比如JAVA 的Eclipse, C#,C++的VisualStudio,最好的Python 开发IDE就是PyCharm 可以直接调试代码,试运行 ...

  10. BZOJ 1232 USACO 2008 Nov. 安慰奶牛Cheer

    [题解] 对于每一条边,我们通过它需要花费的代价是边权的两倍加上这条边两个端点的点权. 我们把每条边的边权设为上述的值,然后跑一边最小生成树,再把答案加上最小的点权就好了. #include<c ...