Avito Code Challenge 2018 A~E
A. Antipalindrome
还以为是什么神dp结果就是分情况讨论啊
原串是一串一样的字符的话输出0,是回文串的话输出n-1,否则直接输出原串长度
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=55;
int n;
char s[N];
int main()
{
scanf("%s",s+1);
n=strlen(s+1);
int f=1;
for(int i=1;i<n;i++)
if(s[i]!=s[i+1])
{
f=0;
break;
}
if(f)
{
puts("0");
return 0;
}
f=1;
for(int i=1;i<=n/2;i++)
if(s[i]!=s[n-i+1])
{
f=0;
break;
}
printf("%d\n",n-f);
return 0;
}
B. Businessmen Problems
hash一下,然后对每个化学元素取收入最大值即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
const int N=200005;
int n,m,a[N],b[N],c[N],d[N],g[N],tot,has,ans[N];
long long sum;
map<int,int>mp;
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
int main()
{
n=read();
for(int i=1;i<=n;i++)
a[i]=read(),c[i]=read(),g[++tot]=a[i];
m=read();
for(int i=1;i<=m;i++)
b[i]=read(),d[i]=read(),g[++tot]=b[i];
sort(g+1,g+1+tot);
for(int i=1;i<=tot;i++)
if(i==1||g[i]!=g[i-1])
mp[g[i]]=++has;
for(int i=1;i<=n;i++)
ans[mp[a[i]]]=c[i];
for(int i=1;i<=m;i++)
ans[mp[b[i]]]=max(ans[mp[b[i]]],d[i]);
for(int i=1;i<=has;i++)
sum+=1ll*ans[i];
printf("%lld\n",sum);
return 0;
}
C. Useful Decomposition
有三种可能情况:所有链在某一点上相交,也就是只有一个点度数>2;只有一条链,就是两个点度数为1,其他点度数为2;不符合要求的情况,就是有超过一个点度数>2
#include<iostream>
#include<cstdio>
using namespace std;
const int N=200005;
int n,d[N],sum,con,p,ans[N],tot;
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
int main()
{
n=read();
for(int i=1;i<n;i++)
{
int x=read(),y=read();
d[x]++,d[y]++;
}
for(int i=1;i<=n;i++)
{
if(d[i]>2)
p=i,sum++;
if(d[i]==1)
ans[++tot]=i,con++;
}
if(sum>1)
{
puts("No");
return 0;
}
if(sum==0)
{
printf("Yes\n1\n%d %d\n",ans[1],ans[2]);
return 0;
}
printf("Yes\n%d\n",con);
for(int i=1;i<=n;i++)
if(d[i]==1)
printf("%d %d\n",p,i);
return 0;
}
D. Bookshelves
很好的dp
或许应该叫按位贪心?从高位到低位枚举,然后f[i][j]表示到j为止分为i段能否让当前枚举的位为1,转移的时候也要注意满足之前枚举的位能不变为0
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=55;
int n,k;
long long a[N],ans;
bool f[N][N];
int main()
{
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++)
scanf("%lld",&a[i]);
for(int i=60;i>=0;i--)
{
memset(f,0,sizeof(f));
f[0][0]=1;
for(int j=0;j<k;j++)
for(int l=0;l<n;l++)
if(f[j][l])
{
long long sum=0;
for(int d=l;d<n;d++)
{
sum+=a[d];
if((sum&ans)==ans&&(sum&(1ll<<i)))
f[j+1][d+1]=1;
}
}
if(f[k][n])
ans|=1ll<<i;
}
printf("%lld\n",ans);
return 0;
}
E. Addition on Segments
还是非常好的dp
设f[i]为i为最大值时出现的最右位置,然后把修改操作按r排序,每次用修改操作更新f即可
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=10005;
int n,q,f[N];
struct qwe
{
int l,r,x;
}a[N];
bool cmp(const qwe &a,const qwe &b)
{
return a.r<b.r;
}
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
int main()
{
n=read(),q=read();
for(int i=1;i<=q;i++)
a[i].l=read(),a[i].r=read(),a[i].x=read();
sort(a+1,a+1+q,cmp);
for(int i=1;i<=q;i++)
{
for(int j=n-a[i].x;j>=1;j--)
if(f[j]>=a[i].l)
f[j+a[i].x]=max(f[j+a[i].x],f[j]);
f[a[i].x]=a[i].r;
}
int ans=0;
for(int i=1;i<=n;i++)
if(f[i]>0)
ans++;
printf("%d\n",ans);
for(int i=1;i<=n;i++)
if(f[i]>0)
printf("%d ",i);
return 0;
}
Avito Code Challenge 2018 A~E的更多相关文章
- Codeforces Avito Code Challenge 2018 D. Bookshelves
Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/ ...
- Codeforces - Avito Code Challenge 2018
Portal A. Antipalindrome 暴力. B. Businessmen Problems 暴力. C. Useful Decomposition 居然不是C打头的?! 将一棵树划分成若 ...
- cf掉分记——Avito Code Challenge 2018
再次作死的打了一次cf的修仙比赛感觉有点迷.. 还好掉的分不多(原本就太低没法掉了QAQ) 把会做的前三道水题记录在这.. A: Antipalindrome emmmm...直接暴力枚举 code: ...
- Avito Code Challenge 2018
第一次打CF,很菜,A了三道水题,第四题好像是是数位DP,直接放弃了.rateing从初始的1500变成了1499,还是绿名,这就很尴尬.之后觉得后面的题目也没有想象的那么难(看通过人数)过两天吧剩下 ...
- Avito Code Challenge 2018 C
C. Useful Decomposition time limit per test 1 second memory limit per test 256 megabytes input stand ...
- [Avito Code Challenge 2018 G] Magic multisets(线段树)
题目链接:http://codeforces.com/contest/981/problem/G 题目大意: 有n个初始为空的‘魔法’可重集,向一个‘可重集’加入元素时,若该元素未出现过,则将其加入: ...
- Avito Cool Challenge 2018 E. Missing Numbers 【枚举】
传送门:http://codeforces.com/contest/1081/problem/E E. Missing Numbers time limit per test 2 seconds me ...
- Avito Cool Challenge 2018 C. Colorful Bricks 【排列组合】
传送门:http://codeforces.com/contest/1081/problem/C C. Colorful Bricks time limit per test 2 seconds me ...
- Avito Cool Challenge 2018 B. Farewell Party 【YY】
传送门:http://codeforces.com/contest/1081/problem/B B. Farewell Party time limit per test 1 second memo ...
随机推荐
- jQuery学习之------对标签属性的操作
jQuery学习之------标签的属性 <a href=””>链接</a>此处的href就是该a标签带有的属性 在js中对标签的属性的操作方法有 1.1getAttribut ...
- Codeforces Round #355 (Div. 2)-B. Vanya and Food Processor,纯考思路~~
B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input s ...
- DRF JWT的用法 & Django的自定义认证类 & DRF 缓存
JWT 相关信息可参考: https://www.jianshu.com/p/576dbf44b2ae DRF JWT 的使用方法: 1. 安装 DRF JWT # pip install djang ...
- 安装K/3 Cloud过程中发现的两个新问题。
卸载掉K/3 Cloud然后重装时出现下面的错误提示: 可能原因: 1.安装目录下的Setup.exe会检查操作系统版本.有些操作系统可能是被串改过注册信息,所以取不到版本信息(有些是因为盗版的原因) ...
- android framework navigationbar自定义
需要实现的目标:在navigationbar上显示录像预览,并且点击按钮可以显示/隐藏NavigationBar 参考文章: http://blog.csdn.net/yanlai20/article ...
- 【ZJOI2017 Round1练习&BZOJ5354】D7T3 room(DP)
题意: 思路: 写了两种版本 考场版本 ..,..]of longint; t:..,..]of longint; n,m,i,j,k,oo,ans,d1:longint; function min( ...
- abs 暴力
Given a number x, ask positive integer y≥2y≥2, that satisfy the following conditions: 1. The absolut ...
- 洛谷 P1555 尴尬的数字
P1555 尴尬的数字 题目背景 Bessie刚刚学会了不同进制数之间的转换,但是她总是犯错误,因为她的两个前蹄不能轻松的握住钢笔. 题目描述 每当Bessie将一个数转换成新的进制时,她总会写错一位 ...
- openstack setup demo Enviroment
Enviroment 本文包含以下部分. Host networking Network Time Protocol (NTP) OpenStack packages SQL database NoS ...
- pkill有的时候并不能杀死进程?
pkill的用法:http://man.linuxde.net/pkill 根据进程命令行,杀死进程 如下intellij.go代码为一个代理服务器,把本地请求转向一个代理 package main ...