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 ...
随机推荐
- 设计模式学习--面向对象的5条设计原则之Liskov替换原则--LSP
一.LSP简介(LSP--Liskov Substitution Principle): 定义:如果对于类型S的每一个对象o1,都有一个类型T的对象o2,使对于任意用类型T定义的程序P,将o2替换为o ...
- 由表生成代码:mybatis-generator入门
application.properties ## mapper xml 文件地址 mybatis.mapper-locations=classpath*:mapper/*Mapper.xml ##数 ...
- SSM配置JDBC错误: cquisition Attempt Failed!!!
异常: 警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@20ffa401 -- Acquisition Attempt Fa ...
- Freemarker详解一
1 截取字符串有的时候我们在页面中不需要显示那么长的字符串,比如新闻标题,这样用下面的例子就可以自定义显示的长度<#if title.content?length lt 8> ...
- 【代码笔记】iOS-iOS图片的原生(Graphics)
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- Git——克隆部分文件
在进行项目开发的时候,有时候会有这样的需求那就是:我们只希望从Git仓库里取指定的文件或者文件夹出来.在SVN里面,这非常容易实现,因为SVN基于文件方式存储,而Git却是基于元数据方式分布式存储文件 ...
- js面向对象设计之class类
class 相对 function 是后出来的,既然 class 出来了,显然是为了解决 function 在处理面向对象设计中的缺陷而来.下面通过对比,来看看 class 作为 ES6 中的重大升级 ...
- flutter控件之RadioButton
import 'package:flutter/material.dart'; class LearnRadioButton extends StatefulWidget{ @override Sta ...
- GridView双击行弹出窗口
protected void gvCustom_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == D ...
- ExpandableListView控件实现二级列表
效果图如下: 二级列表附有点击事件. 1.布局文件: 此处加了一个自定义的导航RelativeLayout,记得注activity的时候添加 android:theme="@style/Th ...