Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round
1)

全场题解

菜鸡只会A+B+C,呈上题解:

A. Bear and Big Brother

题意:我也没看太清,就是给你两个10以内的数a,b。a每天乘以3,b每天乘以2,求多少天后a大于b。

思路:应该是有公式的,不过看到数据这么小直接暴力乘求解。官方题解貌似就是这样,数据小就是水题。

const int N=1e3+10;
int main()
{
int a,b;
while(~scanf("%d%d",&a,&b))
{
if(a>b) puts("0");
else if(a==b) puts("1");
else
{
for(int i=1;;i++)
{
a*=3,b*=2;
if(a>b) {printf("%d\n",i);
break;}
}
}
}
}

B. Bear and
Friendship Condition

题意:如果一个人a与b是好朋友,b又和c是好朋友,那么a和c也应该是好朋友,否则输出NO。现在给你人数n,m种关系,判断YES or NO!

思路:被题解误导了一下,一上午没做出来,中午打会球回来秒A了。这种关系是可以传递的,我们可以用并查集将有关联的集结起来,然后求出每个集合的人数。题目说不会有重边,那么在输出的时候可以求出每个人与多少个人是好朋友,那么假如一个集合的人数为k,那么这k个人肯定要和其余k-1个人是好朋友啊,直接判断就行了。题解给的dfs可能我dfs不是很擅长。

const int N=150000+10;
int n,m,f[N],num[N],sum[N];
int find(int x)
{
return f[x]==-1?x:f[x]=find(f[x]);
}
void solve()
{
memset(sum,0,sizeof(sum));
for(int i=1;i<=n;i++)
{
int x=find(i);
sum[x]++;
}
for(int i=1;i<=n;i++)
{
int x=find(i);
if(num[i]!=sum[x]-1)
{
puts("NO");
return ;
}
}
puts("YES");
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
memset(num,0,sizeof(num));
memset(f,-1,sizeof(f));
int u,v;
for(int i=0; i<m; i++)
{
scanf("%d%d",&u,&v);
int uu=find(u),vv=find(v);
if(uu!=vv) f[uu]=vv;
num[u]++,num[v]++;
}
solve();
}
return 0;
}

C.
Bear and Different Names

怎么感觉C题比B题还简单,挺有意思的,一个模拟构造就行了。

题意:n个人排成一列,每连续k个人组成一个团,一个团的战斗力高要求这k个人姓名都不相同,否则这个团的战斗力低。现在给你1到n-k+1这些团战斗力高低之分,要你找到符合条件的这n个人的名字。数据50以内。

思路:我们可以观察到两个相邻的图只有最前面的那个人与最后面的名字不同,也就是说重复了k-2个人。那么我们可以初始化n个互不相同的字符串(从A开始计数即可).如果当前团是NO,说明有重复的,我们直接让最后一个人的名字等于最前一个人的就行了,下一个团就不包括最前一个人了。这样只要是NO的只需把当前团最后一个人的名字改成当前团最前那个人的就行了。

string s[55]={"0","A", "B", "C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
"Aa","Ab","Ac","Ad","Ae","Af","Ag","Ah","Ia","Ja","Ka","La","Ma","Na","Oa", "Pa", "Qa", "Ra","Sa","Ta","Ua","Va","Wa", "Xa","Ya","Za" };
string str,ans[52];
int main()
{
int n,k;
while(~scanf("%d%d",&n,&k))
{
for(int i=1;i<=n;i++)
ans[i]=s[i];
for(int i=1;i<=n-k+1;i++)
{
cin>>str;
if(str[0]=='N') ans[i+k-1]=ans[i];
}
for(int i=1;i<=n;i++)
cout<<ans[i]<<" ";
cout<<endl;
}
return 0;
}

D题又是一个树搜索,让我这种菜鸡情何以堪1!!!!11

Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!的更多相关文章

  1. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C. Bear and Different Names 贪心

    C. Bear and Different Names 题目连接: http://codeforces.com/contest/791/problem/C Description In the arm ...

  2. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B - Bear and Friendship Condition 水题

    B. Bear and Friendship Condition 题目连接: http://codeforces.com/contest/791/problem/B Description Bear ...

  3. 【树形dp】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) B. Bear and Tree Jumps

    我们要统计的答案是sigma([L/K]),L为路径的长度,中括号表示上取整. [L/K]化简一下就是(L+f(L,K))/K,f(L,K)表示长度为L的路径要想达到K的整数倍,还要加上多少. 于是, ...

  4. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)

    A 模拟 B 发现对于每个连通块,只有为完全图才成立,然后就dfs C 构造 想了20分钟才会,一开始想偏了,以为要利用相邻NO YES的关系再枚举,其实不难.. 考虑对于顺序枚举每一个NO/YES, ...

  5. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)A B C 水 并查集 思路

    A. Bear and Big Brother time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. 【构造】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) A. Bear and Different Names

    如果某个位置i是Y,直接直到i+m-1为止填上新的数字. 如果是N,直接把a[i+m-1]填和a[i]相同即可,这样不影响其他段的答案. 当然如果前面没有过Y的话,都填上0就行了. #include& ...

  7. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) E

    Description Bear Limak prepares problems for a programming competition. Of course, it would be unpro ...

  8. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) D

    Description A tree is an undirected connected graph without cycles. The distance between two vertice ...

  9. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C

    Description In the army, it isn't easy to form a group of soldiers that will be effective on the bat ...

随机推荐

  1. git与GitHub(一)

    相信,很多初入前端者都会对git以及GitHub不太了解,而我当时也经历过各种面试大关,也都会问:你了解git和GitHub吗?那么今天先来说一说git. 那么什么是git? (以下转载自廖雪峰老师的 ...

  2. HDU4035 Maze(期望DP)

    题意 抄袭自https://www.cnblogs.com/Paul-Guderian/p/7624039.html 有n个房间,由n-1条隧道连通起来,形成一棵树,从结点1出发,开始走,在每个结点i ...

  3. C语言abort函数

    C语言编程入门教程,C语言库函数的abort函数的作用是异常终止一个进程,意味着abort后面的代码将不再执行. #include<stdio.h> #include<stdlib. ...

  4. apache下设置域名多站点访问及禁止apache访问80端口

    apache下设置域名多站点访问 当前系统:macOS High Sierra 域名访问配置指定端口后,不同域名只能配置不同的端口 apache配置目录: sudo vim /etc/apache2/ ...

  5. 在SAP CRM WebClient UI中用javascript触发ABAP event

    环境:SAP CRM WebClient UI 需求:在WebClient UI里不通过用户手动点击,而是使用JavaScript代码自动触发ABAP后台的代码. 解决方案: 1. 定义一个hidde ...

  6. halcon相机标定及图像矫正

    https://blog.csdn.net/humanking7/article/details/44756073 相机标定内容详解:转载自 祥的博客 预备知识 标定中的四个坐标系 1.1.平面旋转 ...

  7. div+css实现几种经典布局的详解

    一.左右两侧,左侧固定宽度200px,右侧自适应占满 <div class="divBox"> <div class="left">&l ...

  8. 基于Python的Web应用开发实战——3 模板

    要想开发出易于维护的程序,关键在于编写形式简洁且结构良好的代码. 当目前为止,你看到的示例都太简单,无法说明这一点,但Flask视图函数的两个完全独立的作用却被融合在了一起,这就产生了一个问题. 视图 ...

  9. 利用python进行数据分析2_数据采集与操作

    txt_filename = './files/python_baidu.txt' # 打开文件 file_obj = open(txt_filename, 'r', encoding='utf-8' ...

  10. C-基础:atoi

    C语言库函数名: atoi 功 能: 把字符串转换成整型数. 名字来源:ASCII to integer 的缩写. 原型: int atoi(const char *nptr); 函数说明: 参数np ...