A题

题意:给定一些数,然后求一次交换以后最大的数和最小的数之间的最大距离

分析:找到最大数和最小数的位置,然后判断是把位置大的移到最后还是把位置小的移到开始位置即可

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int maxn=;
int a[maxn];
int main()
{
int n;
while(cin>>n)
{
int minx,maxx;
for(int i=;i<=n;i++)
cin>>a[i];
for(int i=;i<=n;i++){
if(a[i]==)
{
minx=i; break;
}
}
for(int i=;i<=n;i++){
if(a[i]==n){
maxx=i; break;
}
}
if(minx>maxx)
swap(minx,maxx);
cout<<maxx-minx+max(minx-,n-maxx)<<endl;
}
return ;
}

B题

题意:给定一些倒香槟的杯子,第一层1个,第二层2个,依此下去,问第t秒有多少个杯子水是满的

分析:为了考虑精度问题,我们将t乘1024,然后进行模拟,对每1秒流下的水,到下下一层以后一定会变成(a[i][j]-1)/2

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int maxn=;
const int inf=<<;
int a[maxn][maxn];
int n,t;
int main()
{
while(cin>>n>>t)
{
memset(a,,sizeof(a));
a[][]=t*inf;
int ans=;
for(int i=;i<=n;i++)
for(int j=;j<=i;j++){
if(a[i][j]>=inf){
ans++;
a[i+][j]+=(a[i][j]-inf)/;
a[i+][j+]+=(a[i][j]-inf)/;
}
}
cout<<ans<<endl;
}
return ;
}

C题

题意:给定一个字符串,可以改变其中k个字母,问最大的重复字串长度,字符串只含有a和b

分析:这题是一个原题,对于区间[l,r],看其上0的数量是否大于k,若小于k,则[l+1,r]必然也小于k,统计[1,n]上的最大长度即可。统计的时候用二分思想,然后分别对a和b进行统计,最后求其最大值即可。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int maxn=;
char s[maxn];
int a[maxn],b[maxn],dp1[maxn],dp2[maxn];
int n,k;
int main()
{
while(cin>>n>>k)
{
memset(dp1,,sizeof(dp1));
//memset(a,0,sizeof(a));
scanf("%s",s);
for(int i=;i<n;i++){
int t=i;
if(s[i]=='a')
a[++t]=;
else
a[++t]=;
}
//for(int i=1;i<=n;i++)
// cout<<a[i];
//cout<<endl;
for(int i=;i<=n;i++){
if(!a[i])
dp1[i]=dp1[i-]+;
else
dp1[i]=dp1[i-]; }
int left1=,right1=,mx1=,j1=;
for(int i=;i<=n;i++){
while(dp1[i]-dp1[j1]>k) j1++;
if(mx1<i-j1){
mx1=i-j1;
left1=j1+;
right1=i;
}
} memset(dp2,,sizeof(dp2));
//memset(b,0,sizeof(b));
for(int i=;i<n;i++){
int h=i;
if(s[i]=='b')
b[++h]=;
else b[++h]=;
} for(int i=;i<=n;i++){
if(!b[i])
dp2[i]=dp2[i-]+;
else
dp2[i]=dp2[i-];
}
int left2=,right2=,mx2=,j2=;
for(int i=;i<=n;i++){
while(dp2[i]-dp2[j2]>k) j2++;
if(mx2<i-j2){
mx2=i-j2;
left2=j2+;
right2=i;
}
}
cout<<max(mx1,mx2)<<endl;
}
return ;
}

Cdoefroces #354的更多相关文章

  1. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  2. SCUT - 354 - CC的简单多项式 - 杜教筛

    https://scut.online/p/354 跟多项式一点关系都没有. 注意到其实两个多项式在1处求值,那么就是他们的系数加起来. 列一列发现系数就是n以内两两求gcd的值,还自动把0去掉了. ...

  3. <Binary Search> 81 (高频)34 (很难hard, 高频)315 (hard)354

    81. Search in Rotated Sorted Array II 如果中间的数小于最右边的数,则右半段是有序的,若中间数大于最右边数,则左半段是有序的.而如果可以有重复值,就会出现来面两种情 ...

  4. SQLPrompt 6.3.0.354 完美破解 安装于 SQL Server 2012/2014

    SQL SERVER 2012格式化 SQL SERVER 2014格式化 SQLPrompt_6.4.0.641 破解版 百度云下载 迅雷下载 百度网盘下载 SQL Prompt 是一款拥有SQL智 ...

  5. Java实现 LeetCode 354 俄罗斯套娃信封问题

    354. 俄罗斯套娃信封问题 给定一些标记了宽度和高度的信封,宽度和高度以整数对形式 (w, h) 出现.当另一个信封的宽度和高度都比这个信封大的时候,这个信封就可以放进另一个信封里,如同俄罗斯套娃一 ...

  6. 1、线性DP 354. 俄罗斯套娃信封问题

    354. 俄罗斯套娃信封问题 https://leetcode-cn.com/problems/russian-doll-envelopes/ 算法分析 首先我们从两种情况来讨论这个问题: w无重复值 ...

  7. JavaMoney规范(JSR 354)与对应实现解读

    一.概述 1.1 当前现状 当前JDK中用来表达货币的类为java.util.Currency,这个类仅仅能够表示按照**[ISO-4217]**描述的货币类型.它没有与之关联的数值,也不能描述规范外 ...

  8. Codeforces Round #354 (Div. 2)

    贪心 A Nicholas and Permutation #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 ...

  9. leetCode 354. Russian Doll Envelopes

    You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envel ...

随机推荐

  1. oracle提高之索引学习

    一. 索引介绍 1.1  索引的创建 语法 : CREATE UNIUQE | BITMAP INDEX <schema>.<index_name> ON <schema ...

  2. opencv-----基本数据类型

    OpenCV提供了多种基本数据类型.可以在"…/OpenCV/cxcore/include"目录下的cxtypes.h文件中查看其详细定义. CvPoint是一个包含integer ...

  3. jquery 简单的栏目切换

    <style> ul{ list-style:none; padding:0px; margin:0px;} #nav_box{ width:502px; height:402px; ov ...

  4. list遍历

     一.对List的遍历有三种方式            List<String>    list    =    new    ArrayList<String>();    ...

  5. UIRoot

    scalingStyle: Flexible:固定大小,不管设备屏幕的大小是多少,都以固定的像素显示UI Constrained: 可适应屏幕 如要使640*480像素的背景图适应屏幕,要如下设置 c ...

  6. 团队开发里频繁使用 git rebase 来保持树的整洁好吗?

    用了以后, 树可以非常清晰, 某种程度上便于追踪, 但是 push --force 就多多了,不用呢, 合并没有远程仓库被修改的麻烦, 可是追踪又不清晰... git rebase是对commit h ...

  7. 提升html5的性能体验系列之五webview启动速度优化及事件顺序解析]

    webview加载时有3个事件.触发顺序为loading.titleUpdate.loaded.webview开始载入页面时触发loading,载入过程中如果title已经解析并赋予新值,则触发tit ...

  8. shell输出不换行符合换行符

    输出不换行符 例如 echo "Hello\c" echo " World" //Hello World 输出换行符 echo "username\n ...

  9. UAC下的程序权限提升

    来源:http://blog.kingsamchen.com/archives/801 UAC是微软为了提高Windows的安全性,自Windows Vista开始引入的新安全机制. 传统的NT内核系 ...

  10. 关于submit与document.form1.submit();这2个提交的区别

    首先要知道 一个是按钮提交 一个是在js函数里写代码 document.form1.submit() 提交 区别如下: 从使的方式及效主要有二点区别吧.一.使用submit()提交时,表单中不能存在s ...