第一次打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的更多相关文章

  1. Codeforces Avito Code Challenge 2018 D. Bookshelves

    Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/ ...

  2. Codeforces - Avito Code Challenge 2018

    Portal A. Antipalindrome 暴力. B. Businessmen Problems 暴力. C. Useful Decomposition 居然不是C打头的?! 将一棵树划分成若 ...

  3. cf掉分记——Avito Code Challenge 2018

    再次作死的打了一次cf的修仙比赛感觉有点迷.. 还好掉的分不多(原本就太低没法掉了QAQ) 把会做的前三道水题记录在这.. A: Antipalindrome emmmm...直接暴力枚举 code: ...

  4. Avito Code Challenge 2018 C

    C. Useful Decomposition time limit per test 1 second memory limit per test 256 megabytes input stand ...

  5. Avito Code Challenge 2018 A~E

    A. Antipalindrome 还以为是什么神dp结果就是分情况讨论啊 原串是一串一样的字符的话输出0,是回文串的话输出n-1,否则直接输出原串长度 #include<iostream> ...

  6. [Avito Code Challenge 2018 G] Magic multisets(线段树)

    题目链接:http://codeforces.com/contest/981/problem/G 题目大意: 有n个初始为空的‘魔法’可重集,向一个‘可重集’加入元素时,若该元素未出现过,则将其加入: ...

  7. Avito Cool Challenge 2018 E. Missing Numbers 【枚举】

    传送门:http://codeforces.com/contest/1081/problem/E E. Missing Numbers time limit per test 2 seconds me ...

  8. Avito Cool Challenge 2018 C. Colorful Bricks 【排列组合】

    传送门:http://codeforces.com/contest/1081/problem/C C. Colorful Bricks time limit per test 2 seconds me ...

  9. 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 ...

随机推荐

  1. Asp.Net 天气 WebService 使用

    本文使用Asp.Net  (C#)调用互联网上公开的WebServices(http://www.webxml.com.cn/WebServices/WeatherWebService.asmx)来实 ...

  2. Flume - 快速入门

    关于Flume,官方定义如下: Apache Flume is a distributed, reliable, and available system for efficiently collec ...

  3. Session和Cookie的区别与联系

    一. 概念理解 你可能有留意到当你浏览网页时,会有一些推送消息,大多数是你最近留意过的同类东西,比如你想买桌子,上淘宝搜了一下,结果连着几天会有各种各样的桌子的链接.这是因为 你浏览某个网页的时候,W ...

  4. Linux学习8-Linux常用命令(4)

    链接命令     命令名称:ln 命令英文原意:link 命令所在路径:/bin/ln 执行权限:所有用户 功能描述:生成链接文件 语法:ln 选项[-s][原文件] [目标文件] 选项: -s 创建 ...

  5. 【 js 模块加载 】【源码学习】深入学习模块化加载(node.js 模块源码)

    文章提纲: 第一部分:介绍模块规范及之间区别 第二部分:以 node.js 实现模块化规范 源码,深入学习. 一.模块规范 说到模块化加载,就不得先说一说模块规范.模块规范是用来约束每个模块,让其必须 ...

  6. UOJ#410. 【IOI2018】会议

    传送门 首先可以设 \(f[l][r]\) 表示 \([l,r]\) 的答案 设 \(x\) 为区间 \([l,r]\) 的最大值的位置,那么 \(f[l][r] = min(f[l][x-1]+h[ ...

  7. Spring Boot—04文件上传

    package com.smartmap.sample.ch1.controller.view; import java.io.File; import java.io.IOException; im ...

  8. Ubuntu pydot failed to call GraphViz.Please install GraphViz 解决方法

    如果遇到: OSError: `pydot` failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) a ...

  9. hive 排序 order by sort by distribute by cluster by

    order by:     order by是全局排序,受hive.mapred.mode的影响.       使用orderby有一些限制:     1.在严格模式下(hive.mapred.mod ...

  10. 【Java】得到当前股票信息

    import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; ...