Avito Code Challenge 2018
第一次打CF,很菜,A了三道水题,第四题好像是是数位DP,直接放弃了。rateing从初始的1500变成了1499,还是绿名,这就很尴尬。之后觉得后面的题目也没有想象的那么难(看通过人数)过两天吧剩下的五题给补上。
http://codeforces.com/contest/981
A:给你一个字符串S,求把这个字符串中的最长不回文子序列。
思路:
如果S不回文,那就是本身
如果S回文:
(1)如果S由一种字母构成,那么最长不回文子序列为空,因为无论删除多少个都是回文串。
(2)如果S不是上述情况,那么最长不回文就是S.size() - 1
证明:
1、如果S是偶数回文:s1 s2 ... sn sn ... s2 s1
只需要删掉最后的s1即可,变成:s1 s2 ... sn sn ... s2
如果还是回文串,则关于红色部分对称。可以逐渐推导出sn = sn-1 = sn-2 = .. = s2 = s1,那就不满足S不是同一字母构成的前提,所以得证
2、如果S是奇数回文:s1 s2 ... sn ... s2 s1
同理只需要删掉最后的s1即可,变成 s1 s2 ... sn-1 sn sn-1 ... s2
如果还是回文串,也有上述规律。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + ;
const int mod = 1e9 + ;
const double eps = 1e-;
int main()
{
string s, s1;
cin >> s;
for(int i = s.size() - ; i >= ; i--)
{
s1 += s[i];
}
int ans;
if(s1 == s)
{
set<char>c;
for(int i = ; i < s.size(); i++)c.insert(s[i]);
if(c.size() == )ans = ;
else ans = s.size() - ;
}
else ans = s.size();
cout<<ans<<endl;
return ;
}
B:两个公司,每个公司产品编号为ai,价值为bi,给出两个公司的ai,bi,如何使得两个公司的ai各不相同,且bi之和最大。
用map存储最大值即可
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + ;
const int mod = 1e9 + ;
const double eps = 1e-;
int n, m, x, y;
map<int, int>a;
int main()
{
cin >> n;
while(n--)
{
cin >> x >> y;
a[x] = max(a[x], y);
}
cin >> m;
while(m--)
{
cin >> x >> y;
a[x] = max(a[x], y);
}
map<int, int>::iterator it = a.begin();
ll ans = ;
for(; it != a.end(); it++)
{
// cout<<it->first<<" "<<it->second<<endl;
ans += it->second;
}
cout<<ans<<endl;
return ;
}
C:给出一棵树,问这棵树是不是可以分成多条道路,每条边只属于一条道路,每两条道路有一个公共点。输出每条道路的起点和终点(多组解的话任意一组即可)
首先判断什么样的结构满足上述条件。
(1)整棵树就是一条链。满足。
(2)整棵树类似于下图,满足。n-1个点和另一点相连,道路就是每条边。
还有一种情况:
除去红点,所有点的度数均为1或2。
第二种情况就是这种情况的特殊版本。
所以直接判断每个点的度数即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
const int mod = 1e9 + ;
const double eps = 1e-;
int n, m, x, y;
int num[maxn];
int main()
{
cin >> n;
for(int i = ; i < n - ; i++)
{
scanf("%d%d", &x, &y);
num[x]++, num[y]++;
}
int do1 = , do2 = ;
for(int i = ; i <= n; i++)
{
if(num[i] == )do1++;
if(num[i] == )do2++;
}
if(do1 + do2 == n)//情况1
{
int ans[], tot = ;
for(int i = ; i <= n; i++)
if(num[i] == )ans[tot++] = i;
cout<<"Yes\n1\n";
cout<<ans[]<<" "<<ans[]<<endl;
return ;
}
if(do1 + do2 == n - )//情况2,3
{
vector<int>ans;
int id;
for(int i = ; i <= n; i++)
if(num[i] == )ans.push_back(i);
else if(num[i] != )id = i;
cout<<"Yes\n"<<ans.size()<<endl;
for(int i = ; i < ans.size(); i++)
cout<<ans[i]<<" "<<id<<endl;
return ;
}
cout<<"No"<<endl;
return ;
}
Avito Code Challenge 2018的更多相关文章
- 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 C
C. Useful Decomposition time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Avito Code Challenge 2018 A~E
A. Antipalindrome 还以为是什么神dp结果就是分情况讨论啊 原串是一串一样的字符的话输出0,是回文串的话输出n-1,否则直接输出原串长度 #include<iostream> ...
- [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 ...
随机推荐
- WPF Trigger for IsSelected in a DataTemplate for ListBox items
<DataTemplate DataType="{x:Type vm:HeaderSlugViewModel}"> <vw:HeaderSlugView /> ...
- 简单的node爬虫练手,循环中的异步转同步
简单的node爬虫练手,循环中的异步转同步 转载:https://blog.csdn.net/qq_24504525/article/details/77856989 看到网上一些基于node做的爬虫 ...
- 边框圆角Css
.box{ background:grey; //灰色背景 height:50px; //高500像素 width:200px; //宽200像素 border-top-left-radius:15p ...
- ClickOnce 发布WinForm应用程序(非签名方式)
ClickOnce IIS7发布WinForm应用程序,非签名方式(不勾选签名中的"为ClickOnce清单签名") 一.在D盘上建一个文件夹”MyAppPath”. 该 ...
- [日常] CentOS安装最新版redis设置远程连接密码
wget http://download.redis.io/releases/redis-4.0.8.tar.gztar -zxvf redis-4.0.8.tar.gzmake完成后就会放在了src ...
- ibatis中$和#的区别
比如当变量name的类型是Stirng时, $name$ 打印出来的是 张三 #name# 打印出来的是 ‘张三’ $ 的作用实际上是字符串拼接 #用于变量替换 那什么时候用$,什么时候 用 # (1 ...
- Windows上只复制目录结构不复制文件
xcopy /T /E D:\filetest\FB\BK\bs\ D:\filetest\asdf
- javascript中让你捉摸不定的this
this到底指向谁,估计很多人在使用javascript的过程中都遇到过,这个关键字如果没搞懂,在一些高级功能中都会困难重重,搜了下相关文章,介绍的都挺多的,也有很深入的,比如汤姆大叔的<深入理 ...
- div实现返回符,倒三角,椭圆+小知识收集
收集: 1,返回符(伪类元素): .back:before {content: "";width: .3rem;height: .3rem;border-left: .04rem ...
- redis 命令clear、set、get、del、rename、keys *、exists、type、expire、expireat、persist、ttl、move、select
清屏 clear 新增/修改set 查询get 删除del 修改key rename old new 查询所有的key keys *查询一个key是否存在 exists,有返回1,没有返回0查询值的类 ...