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 ...
随机推荐
- 如何使用 Telegram
Telegram是一款加密的实时通讯软件,本文告诉大家如何使用 这个软件. 在使用之前,需要保证自己已经开了梯子,如果没有梯子,那么就无法使用这个工具. 假如梯子是 127.0.0.1 端口 1080 ...
- 【拓扑 && 模板】Kosaraju算法
#include<bits/stdc++.h> using namespace std; ; vector <int> g1[maxn],g2[maxn]; stack < ...
- servlet(一):从Sevlet到HttpServlet
Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中间层. servlet ...
- 哈夫曼编码(Huffman coding)的那些事,(编码技术介绍和程序实现)
前言 哈夫曼编码(Huffman coding)是一种可变长的前缀码.哈夫曼编码使用的算法是David A. Huffman还是在MIT的学生时提出的,并且在1952年发表了名为<A Metho ...
- fzu 2155 盟国
Problem 2155 盟国 Accept: 39 Submit: 129Time Limit: 1000 mSec Memory Limit : 32768 KB Problem De ...
- HNCU专题训练_线段树(2)
1.统计颜色,或运算的运用2.区间第k大数3.一个很经典的题5.求区间相等数字的个数6.RMQ模板题,区间最大值和最小值的差 1.很好的思路,用或运算来避免左右儿子树总相同颜色的情况.由于T颜色种类最 ...
- Android - Builder模式
https://github.com/simple-android-framework-exchange/android_design_patterns_analysis/tree/master/bu ...
- ASP.NET MVC中你必须知道的13个扩展点
ScottGu在其最新的博文中推荐了Simone Chiaretta的文章13 ASP.NET MVC extensibility points you have to know,该文章为我 ...
- NOIP2017 题解
QAQ--由于没报上名并没能亲自去,自己切一切题聊以慰藉吧-- 可能等到省选的时候我就没有能力再不看题解自己切省选题了--辣鸡HZ毁我青春 D1T1 小凯的疑惑 地球人都会做,懒得写题解了-- D1T ...
- CefSharp F12打开DevTools查看console
winform嵌入chrome浏览器,修改项目属性 生成 平台为x86 1.nuget安装cefsharp 2.实例化浏览器 private void Form1_Load(object sender ...