Codeforces Round #479 (Div. 3)解题代码
#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;
}
#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;
}
#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;
}
#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)解题代码的更多相关文章
- Codeforces Round #479 (Div. 3)解题报告
题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #274 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/479 这次自己又仅仅能做出4道题来. A题:Expression 水题. 枚举六种情况求最大值就可以. 代码例如以下: #inc ...
- Codeforces Round #380 (Div. 2) 解题报告
第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...
- Codeforces Round #216 (Div. 2)解题报告
又范低级错误! 只做了两题!一道还被HACK了,囧! A:看了很久!应该是到语文题: 代码:#include<iostream> #include<]; ,m2=; ;i ...
- Codeforces Round #276 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...
- Codeforces Round #350 (Div. 2)解题报告
codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...
- Codeforces Round #271 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/474 A题:Keyboard 模拟水题. 代码例如以下: #include <iostream> #include ...
- Codeforces Round #479 (Div. 3) B. Two-gram
原题代码:http://codeforces.com/contest/977/problem/B 题解:有n个字符组成的字符串,输出出现次数两个字符组合.例如第二组样例ZZ出现了两次. 方法:比较无脑 ...
随机推荐
- IOS开发 序列化与反序列化
原帖地址:http://blog.csdn.net/ally_ideveloper/article/details/7956942 不会用,记下自己有时间看 序列化与反序列化概述 序列化,它又称串行化 ...
- DRBD+Heratbeat+NFS高可用文件共享存储
一.概述 .通过ha-log日志可以看出主释放资源,备接管资源. 来自为知笔记(Wiz)
- mysql字段A复制到字段B,并替换指定字符
',字段a); eg:update `hy_b_pro` set goldWeight=jinJinZhong;
- vue 配置跨域访问
主要在config->index.js中配置 proxyTable: { ‘/gameapi’: { changeOrigin: true, // target: ‘http://rap.id. ...
- MVC的验证(模型注解和非侵入式脚本的结合使用) .Net中初探Redis .net通过代码发送邮件 Log4net (Log for .net) 使用GDI技术创建ASP.NET验证码 Razor模板引擎 (RazorEngine) .Net程序员应该掌握的正则表达式
MVC的验证(模型注解和非侵入式脚本的结合使用) @HtmlHrlper方式创建的标签,会自动生成一些属性,其中一些属性就是关于验证 如图示例: 模型注解 通过模型注解后,MVC的验证,包括前台客 ...
- c++中拷贝构造函数,浅拷贝和深拷贝的区别
在C++提供了一种特殊的构造函数,称为拷贝构造函数.拷贝构造函数具有一般构造函数的所有特性,其作用是使用一个已经存在的对象(由拷贝构造函数的参数指定的对象)去初始化一个新的同类对象,即完成本类对象的复 ...
- 升级iOS 9之前的注意事项
iOS 9 beta刚刚公布.就下载了官网的升级包, 使用itunes的更新功能,升级 眼看安装过程一番顺利, 升级完開始进入设置操作步骤上, 结果傻眼了 进入了输入手机password的界面, 不 ...
- Javascript中的apply、call、bind
apply . call .bind 三者都是用来改变函数的this对象的指向的: apply . call .bind 三者第一个参数都是this要指向的对象,也就是想指定的上下文: apply . ...
- linux kernel编译配置相关
1 配置界面的搜索功能 “/”可以进行模块搜索,搜索结果里面还有依赖信息.非常方便. 2 在使用纯内核,不实用module的时候,很多情况下出错是因为相应的特性为编译进内核 案例一: 块设备已经发现了 ...
- JDK各版本内容和新特性
JDK各版本内容和新特性 - yanlzhl - 博客园 https://www.cnblogs.com/yanlzhl/articles/5694470.html 版本JDK1.0:1995年 ...