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 ...
随机推荐
- AspxGridView中行的双击事件
ClientSideEvents-RowDblClick="clike" function clike(s, e) { grdList.GetRowKey(e. ...
- JavaScript部分兼容性函数
1.getElementsByClassName() function getElementsByClassName(node,classname){ if(node.getElementsByCla ...
- xcode 调试器 LLDB
本文完全转载,转载地址:点击这里 你是否曾经苦恼于理解你的代码,而去尝试打印一个变量的值? NSLog(@"%@", whatIsInsideThisThing); 或者跳过一个函 ...
- myBatis组件之缓存实现及使用
一 .概述 先讲缓存实现,主要是mybatis一级缓存,二级缓存及缓存使用后续补充 Mybatis缓存的实现是基于Map的,从缓存里面读写数据是缓存模块的核心基础功能:除核心功能之外,有很多额外的附加 ...
- 南阳nyoj 509 因子和阶乘
因子和阶乘 时间限制:1000 ms | 内存限制:65535 KB 难度:2 http://acm.nyist.net/JudgeOnline/problem.php?pid=509 描述 给 ...
- ef和mysql使用(二)--让mysql支持EntityFramework.Extended实现批量更新和删除
我们都知道Entity Framework 中不能同时更新多条记录,但是一个老外写的扩展库可以实现此功能EntityFramework.Extended,但是如何是mysql数据库要怎么实现呢 首先实 ...
- react里 MD5加密
https://www.f2td.com/2018/11/13/encrypt-the-user-password-with-md5/
- 地图的可视化--Folium
1.安装folium pip install MarkupSafe-0.23-cp34-none-win_amd64.whl pip install Jinja2-2.8-py2.py3-none-a ...
- SqlServer横向扩展负载均衡终极利器SqlServerProxy 不限功能永久免费
一直以来,MySQL因为开源,诞生了很多扩展方案,类似Amoeba.Atlas.Cobar.MySQLProxy等,大都基于MySQL通信协议来定制解决方案,让我们很羡慕嫉妒,但没办法,Microso ...
- CompletionService和ExecutorCompletionService
CompletionService用于提交一组Callable任务,其take方法返回已完成的一个Callable任务对应的Future对象. 如果你向Executor提交了一个批处理任务,并且希 ...