Codeforces Beta Round #98 (Div. 2)(A-E)
A
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 105
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
char s[N];
int main()
{
int i,j,k;
cin>>s;
k = strlen(s);
int ans = ,g=;
for(i = ; i < k ;i++)
{
if(s[i]!=s[i-])
{
g = ;
ans++;
}
else g++;
if(g>)
{
g = ;
ans++;
}
//cout<<ans<<" "<<g<<" "<<s[i]<<endl;
}
cout<<ans<<endl;
return ;
}
B
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 5050
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int a[N],f[N];
int main()
{
int i,j,n,k;
cin>>n;
for(i =;i <= n; i++)cin>>a[i];
for(i = ;i <= n ;i++)
{
f[a[i]] = ;
}
int ans=;
for(i = ; i<= n; i++)
if(!f[i]) ans++;cout<<ans<<endl;
return ;
}
C
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct node
{
int x,y;
}p[N];
bool cmp(node a,node b)
{
return a.x<b.x;
}
int main()
{
int i,j,n;
cin>>n;
for(i = ; i <= n ;i++)
cin>>p[i].x>>p[i].y;
sort(p+,p+n+,cmp);
int mm = ,ans=;
for(i = ; i <= n ;i ++)
{
if(p[i].y<mm)
ans++;
mm = max(mm,p[i].y); }
cout<<ans<<endl;
return ;
}
D
dp 先预处理出来i-j距离回文串所差的步数 然后D出1-k所需最少的步数 记录一下路径 最后输出
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 505
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
char s[N];
int dp[][],o[][],e[][];
int p[];
int dfs(int i,int j)
{
int a,b;
int o1 = ;
int ii = i,jj = j;
while(ii<jj)
{
if(s[ii]!=s[jj]) o1++;
ii++,jj--;
}
return o1;
}
int main()
{
int i,j,n,kk,k,g;
for(i = ;i <= ; i++)
for(j = ; j <= ; j++)
dp[i][j] = INF;
cin>>s;
kk = strlen(s);
cin>>k;
for(i = ;i < kk ;i++)
for(j = i ; j < kk ;j++)
o[i][j] = dfs(i,j);
for(i = ; i < kk; i++)
{
dp[i][] = o[][i];
}
for(i = ;i < kk ;i++)
for(j = ; j <= min(i+,k) ; j++)
for(g = ; g < i ; g++)
{
if(dp[i][j]>dp[g][j-]+o[g+][i])
{
dp[i][j] = dp[g][j-]+o[g+][i];
e[i][j] = g;
}
}
int minz = INF,x;
for(i = ; i <= k ;i++)
{
if(minz>dp[kk-][i])
{
minz = dp[kk-][i];
x = i;
}
}
cout<<minz<<endl;
if(x==)
{
for(i = ; i < kk/ ; i++)
printf("%c",s[i]);
for(i = (kk-)/ ; i >= ; i--)
printf("%c",s[i]);
return ;
}
g = ;
int ki = kk-;
while(x!=)
{
ki = e[ki][x];
p[g++] = ki;
x--;
}
sort(p,p+g);
for(i = ;i <= p[]/ ; i++)
printf("%c",s[i]);
if(p[])
{
for(i = (p[]-)/ ; i >= ; i--)
printf("%c",s[i]);
}
for(i = ; i < g- ;i++)
{
printf("+");
for(j = p[i]+ ;j <= p[i]+(p[i+]-p[i]+)/ ; j++)
cout<<s[j];
for(j = p[i]+(p[i+]-p[i])/ ;j >= p[i]+ ; j--)
cout<<s[j];
}
if(p[g-]+<kk)
printf("+");
for(i = p[g-]+ ; i <= p[g-]+(kk-p[g-])/ ; i++)
cout<<s[i];
for(i = p[g-]+(kk-p[g-]-)/ ; i >= p[g-]+ ; i--)
cout<<s[i];
cout<<endl;
return ;
}
E
元音-1 辅音+2 开数组sum[i]存前i项和 也就是找最大段(i,j)使sum[j]-sum[i]>=0
这样只存下降的sum数组即可 因为上升的的某个g事不需要的 二分查找第一个小于等于sun[i]的位置 取最大
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 200010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
char s[N];
int sum[N];
struct node
{
int a,po;
}p[N];
int bfind(int l,int h,int k)
{
int m;
while(l<h)
{
m = (l+h)>>;
if(p[m].a<k)
h = m;
else if(p[m].a>k)
l = m+;
else return p[m].po;
}
return p[l].po;
}
int judge(char c)
{
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
return ;
if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
return ;
return ;
}
int main()
{
int i,j,k;
cin>>s;
k = strlen(s);
int g = ;
for(i = ; i < k ;i++)
{
if(i==)
{
if(judge(s[i]))
sum[] = -;
else
sum[] = ;
p[++g].a = sum[i];
p[g].po = i;
}
else
{
if(judge(s[i]))
sum[i] = sum[i-]-;
else
sum[i] = sum[i-]+;
if(sum[i]<p[g].a)
{
p[++g].a = sum[i];
p[g].po = i;
}
}
}
int ans=,cnt=;
for(i = ; i < k ;i++)
{
if(sum[i]>=)
{
ans = i+;
cnt = ;
}
else
{
int o = i-bfind(,g,sum[i]);
//cout<<o<<" "<<i<<" "<<bfind(1,g,sum[i])<<endl;
if(o>ans)
{
ans = o;
cnt = ;
}
else if(o==ans)
cnt++;
}
}
if(ans)
cout<<ans<<" "<<cnt<<endl;
else
puts("No solution");
return ;
}
Codeforces Beta Round #98 (Div. 2)(A-E)的更多相关文章
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
- Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...
随机推荐
- AsyncSocket中tag參数的用处
tag參数是为了在回调方法中匹配发起调用的方法的,不会加在数据传输中. 调用write方法,等待接收消息.收到消息后,会回调didReadData的delegate方法, delegate方法中的ta ...
- var和dynamic的应用 var、动态类型 dynamic 深入浅析C#中的var和dynamic ----demo
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- jquery验证后ajax提交,返回消息怎样统一显示的问题
/* jquery验证后ajax提交.返回消息怎样跟jquery验证体系统一显示的问题,网上查了非常多资料.都没有找到明白的答案,通过数小时的尝试,最终攻克了,现举一个简单的样例,给须要的人參考參考吧 ...
- python3 base64模块代码分析
#! /usr/bin/env python3 """Base16, Base32, Base64 (RFC 3548), Base85 and Ascii85 data ...
- [iOS]经常使用正則表達式
经常使用正則表達式大全!(比如:匹配中文.匹配html) 匹配中文字符的正則表達式: [u4e00-u9fa5] 评注:匹配中文还真是个头疼的事,有了这个表达式就好办了 匹配双字节字符(包含汉字 ...
- Bean Query 第一个版本号(1.0.0)已公布
BeanQuery 是一个把对象转换为Map的Java工具库. 支持选择Bean中的一些属性.对结果进行排序和依照条件查询. 不只能够作用于顶层对象,也能够作用于子对象.很多其它具体的介绍能够看我的博 ...
- [IT学习]Python 小项目 通讯录 思路
建立一个通讯录查询软件,暂时只支持按姓名检索.出发点:无需登录企业门户,即可检索.要注意保护员工手机号,除非他自己同意显示. 欢迎您访问www.cnblogs.com/viphhs.转载请联系作者授权 ...
- java8--异常处理(java疯狂讲义3复习笔记)
try,catch,finally,throw,throws java将异常分为两种,Checked异常和Runtime异常. IndexOutOfBoundsException NumberForm ...
- 深入理解Java执行时数据区
前情回想 在本专栏的前12篇博客中. 我们主要大致介绍了什么是JVM, 而且具体介绍了class文件的格式. 对于深入理解Java, 或者深入理解运行于JVM上的其它语言, 深入理解class文件格式 ...
- 中小企业可参考的数据库架构-mysql篇
引言 数据库在众多互联网公司中应用日益广泛,不同的公司,使用姿势不尽相同,尤其是大公司,各种自研架构,羡煞旁人.但是,作为中小企业,由于分工和团队规模限制,很难实现自研,大多数情况下,使用开源架构. ...