A. Wrong Subtraction

#include <bits/stdc++.h>

using namespace std;

int main()
{
int n,k;
cin>>n>>k;
while(k--)
{
int tmp=n%10;
if(tmp==0)
n/=10;
else n-=1;
}
cout<<n<<endl;
return 0;
}

B. Two-gram

#include <bits/stdc++.h>

using namespace std;
const int MAXN=1000;
char ch[MAXN];
int cnt[MAXN];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>ch[i];
}
for(int i=1;i<=n-1;i++)
{
for(int j=i+1;j<=n-1;j++)
{
if(ch[i]==ch[j]&&ch[i+1]==ch[j+1])
cnt[i]++;
}
}
int index;
int maxnCnt=-1;
for(int i=1;i<=n-1;i++)
{
if(maxnCnt<cnt[i])index=i,maxnCnt=cnt[i];
}
cout<<ch[index]<<ch[index+1]<<endl;
return 0;
}

C. Less or Equal

#include <bits/stdc++.h>

using namespace std;

const int MAXN=200005;
int a[MAXN];
int main()
{
int n,k;
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
if(k==0)
{
if(a[0]>1)cout<<a[0]-1<<endl;
else cout<<-1<<endl;
}
else
{
int tmp=a[k-1];
int cnt=0,flag=0;
for(int i=0;i<n;i++)
{
if(tmp>=a[i])
{
cnt++;
}
else break; }
if(cnt>k)cout<<-1<<endl;
else cout<<tmp<<endl;
} return 0;
}

D. Divide by three, multiply by two

#include <bits/stdc++.h>

using namespace std;
#define LL long long
const int MAXN=120; struct node
{
LL x,y; }a[MAXN];
bool cmp(const node x1,const node x2)
{
if(x1.y!=x2.y)return x1.y>x2.y;
else return x1.x<x2.x;
} LL cnt(LL x)
{
int cnt3=0;
while(x%3==0)
{
cnt3++;
x/=3;
}
return cnt3;
} int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i].x;a[i].y=cnt(a[i].x);
}
sort(a,a+n,cmp);
for(int i=0;i<n;i++)
cout<<a[i].x<<" ";
cout<<endl;
return 0;
}

E. Cyclic Components

#include <bits/stdc++.h>

using namespace std;

const int MAXN=200005;
vector<int>G[MAXN];
bool vis[MAXN]
bool f;
void dfs(int v)
{
vis[v]=1;
if(G[v].size()!=2)
f=1; for(auto x: G[v])
{
if(!vis[x])
dfs(x);
}
}
int main()
{
int n,m,u,v;
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>u>>v;
u--,v--;
G[u].push_back(v);
G[v].push_back(u);
}
int ans=0;
f=0;
for(int i=0;i<n;i++)
{
if(!vis[i])
{
f=0;
dfs(i);
ans+=(!f);
} }
cout<<ans<<endl;
return 0;
}

Codeforces Round #479 (Div. 3)解题代码的更多相关文章

  1. Codeforces Round #479 (Div. 3)解题报告

    题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...

  2. Codeforces Round #324 (Div. 2)解题报告

    ---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...

  3. Codeforces Round #274 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/479 这次自己又仅仅能做出4道题来. A题:Expression 水题. 枚举六种情况求最大值就可以. 代码例如以下: #inc ...

  4. Codeforces Round #380 (Div. 2) 解题报告

    第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...

  5. Codeforces Round #216 (Div. 2)解题报告

    又范低级错误! 只做了两题!一道还被HACK了,囧! A:看了很久!应该是到语文题: 代码:#include<iostream> #include<];    ,m2=;    ;i ...

  6. Codeforces Round #276 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...

  7. Codeforces Round #350 (Div. 2)解题报告

    codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...

  8. Codeforces Round #271 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/474 A题:Keyboard 模拟水题. 代码例如以下: #include <iostream> #include ...

  9. Codeforces Round #479 (Div. 3) B. Two-gram

    原题代码:http://codeforces.com/contest/977/problem/B 题解:有n个字符组成的字符串,输出出现次数两个字符组合.例如第二组样例ZZ出现了两次. 方法:比较无脑 ...

随机推荐

  1. tomcat配置访问项目时不需要加项目名称

    原文:http://blog.csdn.net/coolcoffee168/article/details/52582770 java web部署后,访问项目的时候,需要在地址中添加项目名称,那么如何 ...

  2. Asp.net core使用MediatR进程内发布/订阅

    1.背景 最近,一个工作了一个月的同事离职了,所做的东西怼了过来.一看代码,惨不忍睹,一个方法六七百行,啥也不说了吧,实在没法儿说.介绍下业务场景吧,一个公共操作A,业务中各个地方都会做A操作,正常人 ...

  3. IOS开发 序列化与反序列化

    原帖地址:http://blog.csdn.net/ally_ideveloper/article/details/7956942 不会用,记下自己有时间看 序列化与反序列化概述 序列化,它又称串行化 ...

  4. 【c++】【转】结构体字节对齐

    http://www.cnblogs.com/heyonggang/archive/2012/12/11/2812304.html

  5. 配置Python 2.7.1外加环境pywin32-216.win32-py2.7

    python-2.7.1  安装包 下载地址:http://download.csdn.net/detail/baidu_14854543/7985187 pywin32-216.win32-py2. ...

  6. influxDB系列(一)

    这个是github上面一个人总结的influxDB的操作手册,还不错:https://xtutu.gitbooks.io/influxdb-handbook/content/zeng.html 1. ...

  7. [RxJS] Implement RxJS `mergeMap` through inner Observables to Subscribe and Pass Values Through

    Understanding sources and subscribers makes it much easier to understand what's going on with mergeM ...

  8. 16款创建CSS3动画的jQuery插件

    jQuery插件是用来扩展jQuery原型对象的方法. 本文搜集了用来为你的站点创建CSS3动画的一些jQuery插件. 1. jQuery Smoove Smoove 简化了CSS3转换效果.使得页 ...

  9. LoadRunner 比较字符串是否相等

    int strcmp ( const char *string1, const char *string2 );大小写敏感.int stricmp ( const char *string1, con ...

  10. mac WebStorm 破解

    摘要:因为想要学习HTML所以需要一个工具,同事推荐了webstorm.下载以后再网上搜破解方法.搜索到一个很简单的. 一.下载链接https://www.jetbrains.com/webstorm ...