Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!
Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round
1)
菜鸡只会A+B+C,呈上题解:
题意:我也没看太清,就是给你两个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题比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!的更多相关文章
- 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 ...
- 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 ...
- 【树形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的整数倍,还要加上多少. 于是, ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)
A 模拟 B 发现对于每个连通块,只有为完全图才成立,然后就dfs C 构造 想了20分钟才会,一开始想偏了,以为要利用相邻NO YES的关系再枚举,其实不难.. 考虑对于顺序枚举每一个NO/YES, ...
- 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 ...
- 【构造】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& ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- SpringBoot实现登陆拦截
一.创建interceptor包,在interceptor中创建一个拦截器并实现HandlerInterceptor 代码: @Componentpublic class LoginHandlerIn ...
- vue从入门到开发--4--处理http请求
一: 在main.js里面处理http请求模块,因为没有这个模块,所以需要先安装这个模块:npm install vue-resource --save 安装完毕之后,导入这个模块,并使用中间件将其使 ...
- iOS 画圆图片的几种方法
方法一: self.cycleImv= [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 50, 50)]; [self.view addS ...
- 我的CentOS6.5下及windows7下 安装composer与Yii2的过程
用yii2以来,安装composer老是不成功,所以一直在windows下的php里,用直接解压的方法运行yii2. 后来越来越多的场合,需要用composer,终于下决心,要在Linux下搞掂它! ...
- 面向阿里云专家的 Azure 云服务介绍
本文是面向阿里云专家的 Azure 云服务介绍,参考本文可以帮助大家“按图索骥”在 Azure 的平台上找到能满足自己需求的服务. 在公有云计算蓬勃发展的同时,中国也出现了越来越多的本土公有云平台.针 ...
- Azure 项目构建 – 部署 Jenkins 服务器以实现持续集成(CI)
通过完整流程详细介绍了如何通过 Azure 虚拟机.虚拟网络等服务在 Azure 平台上快速搭建 Jenkins 服务器. 此系列的全部课程 https://school.azure.cn/curri ...
- MyBatis插入数据之后返回插入记录的id
MyBatis插入数据的时候,返回该记录的id<insert id="insert" keyProperty="id" useGeneratedKeys= ...
- 交互干货必收 | App界面交互设计规范
原文地址:http://www.woshipm.com/ucd/193776.html
- 数据倾斜是多么痛?spark作业调优秘籍
目录视图 摘要视图 订阅 [观点]物联网与大数据将助推工业应用的崛起,你认同么? CSDN日报20170703——<从高考到程序员——我一直在寻找答案> [直播]探究L ...
- Sublime 设置移动光标快捷键
发现问题 在使用Sublime和其他编辑器一个很不爽的问题是:在输入一个函数或者有左右的符号或者在引号内时,总是要跳出来,无奈方向键又在主键盘的另一边,只能不断的切换,太特么操蛋,就不能让手指不离开主 ...