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出现了两次. 方法:比较无脑 ...
随机推荐
- Linux源代码分析工具-Source Insight
下载地址:http://www.sourceinsight.com/down35.html 可用注冊码:SI3US-205035-36448 使用说明:http://wenku.baidu.com/v ...
- USACO castle
<pre name="code" class="cpp"><pre>USER: Kevin Samuel [kevin_s1] TASK ...
- csv读入数据,用julia/matplotlib/pyplot 画矢量图导入word中
这是是用julia来实现画图.julia有三个画图库:Winston.Gadfly.PyPlot 这里用的是pyplot,事实上他是基于matplotlib的 1.首先在juno里安装两个库 juno ...
- spinlock in linux kernel
spinlock in linux kernel 作为一种锁机制, spinlock可以制造一段临界区, 同一时刻只有一个线程能进入这个临界区, 从而达到保护数据的目的. semaphore, mut ...
- 嵌入式开发之davinci---dm8168VPORT口管脚总结
http://blog.csdn.net/shanghaiqianlun/article/details/7531365
- pymssql.connect(server='.', user='', password='', database='', timeout=0, login_timeout=60, charset='UTF-8', as_dict=False, host='', appname=None, port='1433', conn_properties, autocommit=False, tds_
http://pymssql.org/en/stable/ref/pymssql.html """ This is an effort to convert the py ...
- LEA指令与MOV指令的区别——发现一本汇编好书
一.汇编语言中PTR的含义及作用mov ax,bx ;是把BX寄存器“里”的值赋予AX,由于二者都是word型,所以没有必要加“WORD”mov ax,word ptr [bx];是把内存地址等于“B ...
- SQL Server 2012 从备份中还原数据库
1.首先把原数据库备份,检查原数据库的日志文件是否太大,如果过于大应该先收缩数据库日志 2.把备份的数据库文件在目标SQL Server还原,点击数据库,选择“还原文件或文件组” 3.如果需要修改还原 ...
- 如何写好react组件
react 组件方面: 总结 React 组件的三种写法 及最佳实践 [涨经验] React组件编写思路(一) 使用react-router实现单页面应用时设置页面间过渡的两种方式 [翻译]基于 Cr ...
- Linux下使用putty进行UART串口调试【转】
本文转载自:http://blog.csdn.net/xzongyuan/article/details/11593101 版权声明:本文为博主原创文章,未经博主允许不得转载. 使用putty进行串口 ...