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 ...
随机推荐
- libevent API 介绍
基本应用场景也是使用 libevnet 的基本流程,下面来考虑一个最简单的场景,使用livevent 设置定时器,应用程序只需要执行下面几个简单的步骤即可. 1)首先初始化 libevent 库,并保 ...
- WEB服务器安装oracle jdbc
WEB服务器,如果想采用jdbc访问另一台Oracle数据库服务器,那么它应该先安装Oracle客户端,或者要安装oracle jdbc. 那么怎样安装oracle jdbc呢? 1.到oracle下 ...
- while语句字符串的基本操作
1,编码:对现在通用文字编码成计算机文字,便于储存,传递,交流. 最早的计算机编码是ACSII美国人创建的,包含英文字母,数字,以及特殊符号.总共是128个码位:2**7,因为计算机的底层只能识别:& ...
- POJ之01背包系列
poj3624 Charm Bracelet 模板题 没有要求填满,所以初始化为0就行 #include<cstdio> #include<iostream> using na ...
- 将最大主机/ DNS名称字符长度从63增加到255
https://mp.weixin.qq.com/s/WcjaAgAOvEhjtP2nXx5Fhw Zabbix 4.0.0alpha8发行说明 运维帮 昨天 Zabbix团队很高兴地宣布Zabbix ...
- XMU 1606 nc与滴水问题 【模拟】
1606: nc与滴水问题 Time Limit: 1000 MS Memory Limit: 64 MBSubmit: 85 Solved: 27[Submit][Status][Web Boa ...
- UVA10462Is There A Second Way Left? —— 次小生成树 kruskal算法
题目链接:https://vjudge.net/problem/UVA-10462 Nasa, being the most talented programmer of his time, can’ ...
- centos7和redhat7的比特币环境搭建
比特币版本是 bitcoin-0.12 问题1: [root@localhost bitcoin-master]# ./autogen.sh which: no autoreconf in (/us ...
- javascript 二级联动
<html> <head> <title></title> <meta http-equiv="Content-Type" c ...
- yii2.0 ActiveRecord 查询汇总
User::find()->all(); 此方法返回所有数据: User::findOne($id); 此方法返回 主键 id=1 的一条数据(举个例子): User::find()->w ...