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 ...
随机推荐
- 在linux服务器上搭建Struts2项目运行环境
服务器上工作: 首先要先装java https://www.cnblogs.com/lamp01/p/8932740.html 然后装好tomcat https://www.cnblogs.com/y ...
- 添物不花钱学JavaEE(基础篇)- Java
Java Java是一面向对象语言 Write Once Run Anywhere Designed for easy Web/Internet applications, Mobile Widesp ...
- 【重要】MySQL常见面试题
1. 主键 超键 候选键 外键 主 键: 数据库表中对储存数据对象予以唯一和完整标识的数据列或属性的组合.一个数据列只能有一个主键,且主键的取值不能缺失,即不能为空值(Null). 超 键: 在关系中 ...
- hdu - 1072 Nightmare(bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1072 遇到Bomb-Reset-Equipment的时候除了时间恢复之外,必须把这个点做标记不能再走,不然可能造 ...
- [bzoj3630][JLOI2014]镜面通道_计算几何_网络流_最小割
镜面通道 bzoj-3630 JLOI-2014 题目大意:题目链接. 注释:略. 想法: 我们发现,只要上下界没有被完全封死,我们就一定有一条合法的光路. 所以只需要将上界和下界拆开即可. 拆点,把 ...
- Android GIS开发系列-- 入门季(11) Callout气泡的显示
一.气泡的简单显示 首先我们要获取MapView中的气泡,通过MapView的getCallout()方法获取一个气泡.看一下Callout的简单介绍: 大体的意思是通过MapView获取Callou ...
- CentOS系统下Hadoop、Hbase、Zookeeper安装配置
近期给一个项目搭建linux下的大数据处理环境,系统是CentOS 6.3.主要是配置JDK.安装Tomcat,Hadoop.HBase和Zookeeper软件.博主在Hadoop这方面也是新手.配置 ...
- socker地址API
大端字节序是指一个整数的高位字节存储在内存的低地址处,低位字节存储在内存的高地址处.小端字节序是指整数的高位字节存储在内存的高地址处,低位字节则存储在内存的低地址处. 现代pc大多采用小端字节序,故小 ...
- Centos7最小安装下Install Clamav(2017-06-09最后更新)
If you are installing ClamAV for the first time, you have to add a new user and group to your system ...
- Windows 7 SID 修改
在安裝Windows系統時會產生一個獨一無二的SID (Security ID),它用來識別每一部主機,若在同一個區域網路內有兩部相同SID的主機,會出現警告訊息.一般而言,每次安裝時的SID不可能會 ...