codeforces411div.2
每日CF:
411div2
| Solved | A | CodeForces 805A | Fake NP | |
| Solved | B | CodeForces 805B | 3-palindrome | |
| Solved | C | CodeForces 805C | Find Amir | |
| Solved | D | CodeForces 805D | Minimum number of steps | |
|
Attempted |
E | CodeForces 805E | Ice cream coloring | |
| F | CodeForces 805F | Expected diameter of a tree |
点题号阅读题面
---------
A
题意:
给a,b,求[a,b]中所有整数的所有除数中,最多的一个
分析:
水题,直接看代码
/**********************
*@Name:
*
*@Author: Nervending
*@Describtion:
*@DateTime:
***********************/
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+;
const int INF=0x3f3f3f3f;
int n,m,k;
int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif cin>>n>>m;
if(m==n) cout<<m;
else cout<<; #ifdef test
fclose(stdin);
fclose(stdout);
system("out.txt");
#endif
return ;
}
---------
B
题意:
求一个长度为n的字符串,由a,b,c三个字符组成
要求不能出现长度为3的回文串,且c的出现次数最低
分析:
是不出现长度''恰好''好为3的回文串
经过简单的思考和实验,
显然aabb的无限重复,只会出现长度为偶数的回文串,符合题意
/**********************
*@Name:
*
*@Author: Nervending
*@Describtion:20min
*@DateTime:2018-02-02 16:16:38
***********************/
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+;
const int INF=0x3f3f3f3f;
int n,m,k; int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
cin>>n;
for(int i=;i<=n;i++){
if(i%==||i%==)printf("a");
else printf("b");
}
#ifdef test
fclose(stdin);
fclose(stdout);
system("out.txt");
#endif
return ;
}
-----
C
题意:
1-n一共n个节点,两个节点之间的距离等于两个节点编号之和对n+1取模,每次访问完两个节点,两个节点的距离花费为0
求遍历所有点的最小花费
分析:
显然,i+j==n+1时最优,次优为i+j==n+2
具体看代码
/**********************
*@Name:
*
*@Author: Nervending
*@Describtion:
*@DateTime:2018-02-02 16:16:38
***********************/
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+;
const int INF=0x3f3f3f3f;
int n,m,k; int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
cin>>n;
if(!(n&)) cout<<n/-;
else cout<<n/;
#ifdef test
fclose(stdin);
fclose(stdout);
system("out.txt");
#endif
return ;
}
-----
D
题意:
给一个由a,b组成的字符串,进行如下操作:
把所有"ab"子串,换为"bba"
求最少的操作次数,答案对1e9+7取余
分析:
递推题
如果是简单的"ab"换为"ba",很明显答案就是整个字符串进行冒泡排序的次数
但这里换成的"bba",显然,本质上依然是冒泡排序
但是每次交换会多出来一个b,也就是简单的递推
预打表操作n次后的冒泡次数
再预处理每个位置之前a的个数
求和即可
/**********************
*@Name:
*
*@Author: Nervending
*@Describtion:
*@DateTime:2018-02-02 16:16:38
***********************/
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+;
const int mod=1e9+;
const int INF=0x3f3f3f3f;
int n,m,k;
char s[maxn];
int numa[maxn];
int ans[maxn];
int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
ans[]=;
for(int i=;i<=maxn;i++){
ans[i]=(((ans[i-]<<)%mod)+)%mod;
}
scanf("%s",s+);
n=strlen(s+);
for(int i=;i<=n;i++){
numa[i]=numa[i-];
if(s[i]=='a')numa[i]++;
}
long long time=;
for(int i=;i<=n;i++){
if(s[i]=='b')time=(time+ans[numa[i]])%mod;
}
cout<<time<<endl;
#ifdef test
fclose(stdin);
fclose(stdout);
system("out.txt");
#endif
return ;
}
-----
E
没写完E...题意比较麻烦,读错了
题意:
给一个树,每个节点包含一个数字集合,其中有相同元素的节点一定组成一个连通子图
然后建立一个新图,把树上所有有相同元素的连边,组成一个完全子图
接下来进行图上的染色,最终保证所有相邻点没有一样的颜色
求所有颜色和一种染色方式
分析:
(出来看了题解,写出来的)
图论思维题,树上的dfs
所有相邻点一定构成一个连通子图,就意味着所有一样颜色的点一定在同样一个子树上
然后新图中连边,显然所有有一样元素的节点一定是相邻的
具体过程采用dfs,由于原图中颜色一样就在一个子树上,所以直接dfs不会出现问题
注意,可能会出现节点是空集合,注意避免
/**********************
*@Name:
*
*@Author: Nervending
*@Describtion:
*@DateTime: 2018-02-02 17:15:12
***********************/
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+;
const int maxm=1e6+;
const int mod=1e9+;
const int INF=0x3f3f3f3f;
typedef set<int>::iterator sit;
int n,m,k;
set<int>s[maxn];
vector<int>g[maxn];
int ans[maxn];
int head[maxn],nume;
int cnt;
struct node{
int to,next;
}e[maxm];
void add(int a,int b){
e[nume]=(node){b,head[a]};
head[a]=nume++;
}
void dfs(int now,int pre){
vector<int>vis;
sit end=s[now].end();
if(pre==-){
for(sit i=s[now].begin();i!=end;i++){
ans[(*i)]=++cnt;
}
}else {
for(sit i=s[now].begin();i!=end;i++){
if(ans[(*i)]){
vis.push_back(ans[(*i)]);
}
}
sort(vis.begin(),vis.end());
int num=vis.size();
int j=,son=;
for(sit i=s[now].begin();i!=end;i++){
if(!ans[(*i)]){
while(j<num){
if(son==vis[j]){
j++,son++;
}
else break;
}
ans[(*i)]=son++;
}
cnt=max(cnt,son-);
}
}
for(int i=head[now];~i;i=e[i].next){
int to=e[i].to;
if(to!=pre){
dfs(to,now);
}
}
} int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int n,m;
memset(head,-,sizeof head);
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
int a;
scanf("%d",&a);
for(int j=;j<a;j++){
int b;
scanf("%d",&b);
s[i].insert(b);
}
}
for(int i=;i<n-;i++){
int a,b;
scanf("%d%d",&a,&b);
add(a,b);
add(b,a);
}
memset(ans,,sizeof ans);
cnt=;
dfs(,-);
printf("%d\n",max(,cnt));
for(int i=;i<=m;i++){
if(ans[i])printf("%d ",ans[i]);
else printf("1 ");
}
#ifdef test
fclose(stdin);
fclose(stdout);
system("out.txt");
#endif
return ;
}
codeforces411div.2的更多相关文章
随机推荐
- shiro的基本认识及做一个简单的授权登陆的例子
先推荐一个网站,无意中发现的.感觉蛮好的. 推荐一套完整的Shiro Demo,免费的.Shiro Demo:http://www.sojson.com/shiroDemo已经部署到线上,地址是htt ...
- Ado.NET基础必备
一.SqlConnection对象 第一次需要连接数据库时要和服务器握手,解析连接字符串,授权,约束的检查等等操作,而物理连接建立后,这些操作就不会去做了(默认使用了连接池技术). SqlConnec ...
- 详解Linux内核红黑树算法的实现
转自:https://blog.csdn.net/npy_lp/article/details/7420689 内核源码:linux-2.6.38.8.tar.bz2 关于二叉查找树的概念请参考博文& ...
- try{s.send(t.hasContent&&t.data||null)}catch(e){if(n)throw e}}引发的惨案
如题,ajax请求报错:try{s.send(t.hasContent&&t.data||null)}catch(e){if(n)throw e}}引发的惨案 要么是404,要么是40 ...
- PHPMYWIND4.6.6前台Refer头注入+后台另类getshell分析
下载链接 https://share.weiyun.com/b060b59eaa564d729a9347a580b7e4f2 Refer头注入 全局过滤函数如下 function _RunMagicQ ...
- 解析ArcGis的字段计算器(二)——有玄机的要素Geometry属性,在属性表标记重复点线面
这里所说的重复是指完成重复的,不是叠在一起的两个或多个要素,这种应该叫做“压盖”或“重叠”.重复往往是在合并多Shpfile文件时不小心重复导入造成的. 这里提供一种可能的解决办法,数据无价,请备份! ...
- Js点击按钮下载文件到本地(兼容多浏览器)
实现点击 用纯 js(非jquery) 下载文件到本地 自己尝试,加网上找了好久未果,如: window.open(url) location.href=url form表单提交 ifr ...
- 使用 CROSS APPLY 与 OUTER APPLY 连接查询
Ø 前言 日常开发中遇到多表查询时,首先会想到 INNER JOIN 或 LEFT OUTER JOIN 等等,但是这两种查询有时候不能满足需求.比如,左表一条关联右表多条记录时,我需要控制右表的某 ...
- 经典文摘:饿了么的 PWA 升级实践(结合Vue.js)
自 Vue.js 官方推特第一次公开到现在,我们就一直在进行着将饿了么移动端网站升级为 Progressive Web App 的工作.直到近日在 Google I/O 2017 上登台亮相,才终于算 ...
- transition的属性变化
链接:https://www.cnblogs.com/yehui-mmd/p/5934157.html css3——transition属性和opacity属性 [transition-durat ...