当前位置:网站首页>Codeforces Round #657 Div. 2
Codeforces Round #657 Div. 2
2022-06-29 10:09:00 【It's mally!】
Codeforces Round #657 Div. 2
notes
| type | difficulty | |
|---|---|---|
| 1379A. cacius and String | violence , About strings | 2 |
| 1379B. Dubious Cyrpto | About Mathematics | 1 |
| 1379C. Choosing flowers | Sort | 3 |
1379A. Acacius and String
solution : violence
The question : Give a length of n String , By lowercase letters and ‘?‘ form , Now we can put ’?‘ Replace , Ask if you can make the final result ’abacaba‘ Only once .
My thoughts :
First, check the original string ‘abacaba’ Several times , Record as already
If already>1, Output no
If already=1, hold ’?‘ Replace with ’d’, Then the output
If alrady=0, It is found that it can be successfully replaced with ”abacaba“ The location of , Just take the rest ‘?’ become ‘d’, Then the output .
Now wa 了 ,wa Why :
It is found that it can be successfully replaced with ”abacaba“ The location of , It should be checked whether the replacement can guarantee already by 1, And then output .
After correction ac The code is as follows
#include "bits/stdc++.h"
using namespace std;
string ss,tem;
int n;
const char standard[]="abacaba";
int check(string ff)
{
int cnt=0;
for(int d=0;d+6<n;++d)
{
int suc=1;
for(int k=0;k<=6;++k)
if(standard[k]!=ff[d+k]){suc=0;
break;}
if(suc)++cnt;
if(cnt>1)return cnt;
}
return cnt;
}
int possible(int i)
{
for(int k=0;k<=6;++k)
{
if(ss[i+k]=='?')continue;
if(ss[i+k]!=standard[k])return 0;
}
return 1;
}
int main()
{
// freopen("in.text","r",stdin);
int cas;
scanf("%d",&cas);
while (cas--)
{
cin>>n>>ss;
int already=check(ss);
if(already>1)
{
printf("No\n");
continue;
}
else if(already==1)
{
printf("Yes\n");
for(int i=0;i<n;++i)if(ss[i]=='?')ss[i]='d';
cout<<ss<<endl;
}
else if(already==0)
{
int suc=0;
for(int i=0;i+6<n;++i)
if(possible(i)){
tem=ss;
for(int d=0;d<=6;++d)tem[i+d]=standard[d];
if(check(tem)==1)
{
suc=1;
for(int d=0;d<n;++d)if(tem[d]=='?')tem[d]='d';
break;
}
}
if(suc)cout<<"Yes"<<endl<<tem<<endl;
else cout<<"No"<<endl;
}
}
return 0;
}
1379C Choosing flowers
The question : Yes m grow flowers , The happiness of buying a bunch of flowers is a i a_i ai, buy k The happiness of a bouquet of flowers is a i + ( k − 1 ) b i a_i+(k-1)b_i ai+(k−1)bi , Now I want to buy n Bouquet of flowers , Ask the maximum happiness value .
Ideas :
There must be many answers a Attribute flowers and 1 Kind of b Attribute flower ,why?
Let's assume that there are many kinds of a Attribute flower , and b 1 , b 2 b_1,b_2 b1,b2, Then if b 1 b_1 b1 Greater than b 2 b_2 b2, Since infinity , Why? b 2 b_2 b2 Well .
Then choose by enumerating b i b_i bi grow flowers , Must be greater than b i b_i bi Of a flowers , So use the prefix and calculate in advance .
Algorithm :
Press... On the flowers a Attribute value ordering jiejing
enumeration b i b_i bi, Two points Find out how many are greater than b i b_i bi Of a i a_i ai, Add the corresponding prefix and .
The complexity of the algorithm is O ( m ∗ l o g ( m ) ) O(m*log(m)) O(m∗log(m))
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int MAXN=1E5+10;
struct re{
ll a,b;
re(ll k1=0,ll k2=0): a(k1),b(k2){}
bool operator< (const re &it)const
{
return a>it.a;
}
};
re flower[MAXN];
ll presum[MAXN];
int main()
{
// freopen("in.text","r",stdin);
int cas,n,m;
scanf("%d",&cas);
while (cas--)
{
scanf("%d %d",&n,&m);
for(int i=1;i<=m;++i)scanf("%lld %lld",&flower[i].a,&flower[i].b);
sort(flower+1,flower+1+m);
presum[0]=0;
for(int i=1;i<=m;++i)presum[i]=presum[i-1]+flower[i].a;
ll ans=0;
for(int i=1;i<=m;++i)
{
int xu=upper_bound(flower+1,flower+1+m,re(flower[i].b,0) )-flower-1;
ll now;
if(xu>=n){ now=presum[n];;}
else if(xu<i)
{
now=presum[xu]+flower[i].a+(n-1-xu)*flower[i].b;
} else if(xu>=i)
{
now=presum[xu]+(n-xu)*flower[i].b;
}
ans=max(now,ans);
}
printf("%lld\n",ans);
}
}
边栏推荐
- A 3D Dual Path U-Net of Cancer Segmentation Based on MRI
- 2020-09-25 boost库的noncopyable,用于单例模式
- Language characteristics
- 2020-09-18 referer认证 url转义
- Pipeline details of IPC (interprocess communication)
- 2019.11.13训练总结
- Set up lamp environment under cenos7
- Leetcode MySQL database topic 178
- Leetcode MySQL database topic 177
- ImageView图片填充问题
猜你喜欢
随机推荐
acwing271【杨老师的照相排列】【线性DP】
Student addition / deletion gaih
2019.11.20训练总结
container
Community Union
弧形 View 和弧形 ViewPager
Power Strings【KMP循环节】
Wechat applet realizes store function
分布式和集群分不清,我们讲讲两个厨子炒菜的故事
Flutter 基础组件之 Container
Leetcode MySQL database topic 181
Constructing SQL statements by sprintf() function in C language
C语言中通过sprintf()函数构造sql语句
JVM之方法的绑定机制
2020-09-23左右值 右值引用 std::move()
2020-09-21 referer字符串切分 boost gateway代码组织层次
leetcode MYSQL数据库题目176
RecyclerView 通用适配器封装
2019icpc上海区域赛赛后总结
Generic paging framework








