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 ...
随机推荐
- 解决UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 12: ordinal not in range(128)的编码问题
当我在运行一个基于scrapy的爬虫时出现UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 12: ordina ...
- 【HRS项目】Axure兴许问题解决---与SVN结合
上一篇博客介绍了Axure的团队开发用法,http://blog.csdn.net/u013036274/article/details/50999139,可是再用的时候发现会出现这种问题,例如以下图 ...
- [数据集]新浪微博数据集MicroblogPCU
数据集下载地址:下载 摘要:MicroblogPCU是从新浪微博採集到的.它能够被用于研究机器学习方法和社会关系研究. 这个数据集被原作者用于探索微博中的spammers(发送垃圾信息的人).他们的d ...
- STM32通过调用库函数进行编程
1.调用库函数编程和直接配置寄存器编程的差别: 2.CMSIS标准: 3.STM32库函数的组织: 4.程序例举: 调用库函数实现通过USART发送数据(26个大写的英文字母) 首先:在主函数部分先要 ...
- udhcp源码详解(四) 之租赁IP的管理
Server端对于租赁出去的IP的管理是基于结构体dhcpOfferedAddr的,该结构体的定义是在leases.c文件里:(结构体的成员介绍说明见详解之数据结构) 1: struct dhcpOf ...
- MySql InnoDb还原工具
通过任意文件下载找到了mysql的备份,表类型是独享式innodb,由一个frm文件和一个ibd文件组成. 本以为直接复制到本地的mysql数据目录中即可恢复数据,但在查询时却发现并不如所愿: mys ...
- CronTab命令实例
每2分钟 将date写入到time.log(以下的为奇数分钟运行) */2 * * * * date >> ~/time.log 1-59/2 * * * * date >> ...
- 注入式开发(二):.NET 匿名函数
其实匿名函数就是个委托.只不过写起来更简洁. 为啥要用匿名函数呢?只是为了装逼吗? 诺诺诺 比如说,我们写代码,写着写着,发现有2个函数非常相像: string methodA(string data ...
- XMU 1050 Diffuse Secret 【最短路】
1050: Diffuse Secret Time Limit: 500 MS Memory Limit: 64 MBSubmit: 10 Solved: 8[Submit][Status][We ...
- bzoj5333: [Sdoi2018]荣誉称号
请不要去改题目给的输入,不然你会wa穿... 这么故弄玄虚的题目,肯定要先转换问题 看到这个不断的除2想起别人家的线段树的写法...x的两个孩子是x<<1和x<<1|1 然后问 ...