2018SDIBT_国庆个人第五场
A - ACodeForces 1060A
Description
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have $$$n$$$ cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer $$$n$$$ — the number of cards with digits that you have ($$$1 \leq n \leq 100$$$).
The second line contains a string of $$$n$$$ digits (characters "0", "1", ..., "9") $$$s_1, s_2, \ldots, s_n$$$. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Sample Input
11
00000000008
1
22
0011223344556677889988
2
11
31415926535
0
Hint
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards.
题意:问你能组成多少个电话号码 像8xxxxxxxxxx的,给你n个卡片,每个卡片只能用一次或者不用
分析:不用考虑电话号码里具体的排列
1:如果给出的卡片没有8或者卡片数量小于11,直接输出0
2:t=卡片数除以11,如果t的数量大于号码为8的卡片的数量,则输出8的数量,否则输出t
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
int n,a[];
char s[];
while(~scanf("%d",&n))
{
memset(a,,sizeof(a));
scanf("%s",s);
for(int i=;i<n;i++)
{
a[s[i]-'']++;
}
if(a[]==||n<)
printf("0\n");
else
{
int t=n/;
if(a[]>t)
{
printf("%d\n",t);
}
else
printf("%d\n",a[]);
}
}
return ;
}
B-codeforces 1060B
Description
You are given a positive integer nn.
Let S(x)S(x) be sum of digits in base 10 representation of xx, for example, S(123)=1+2+3=6S(123)=1+2+3=6, S(0)=0S(0)=0.
Your task is to find two integers a,ba,b, such that 0≤a,b≤n0≤a,b≤n, a+b=na+b=n and S(a)+S(b)S(a)+S(b) is the largest possible among all such pairs.
Input
The only line of input contains an integer nn (1≤n≤1012)(1≤n≤1012).
Output
Print largest S(a)+S(b)S(a)+S(b) among all pairs of integers a,ba,b, such that 0≤a,b≤n0≤a,b≤n and a+b=na+b=n.
Sample Input
35
17
10000000000
91
Hint
In the first example, you can choose, for example, a=17a=17 and b=18b=18, so that S(17)+S(18)=1+7+1+8=17S(17)+S(18)=1+7+1+8=17. It can be shown that it is impossible to get a larger answer.
In the second test example, you can choose, for example, a=5000000001a=5000000001 and b=4999999999b=4999999999, with S(5000000001)+S(4999999999)=91S(5000000001)+S(4999999999)=91. It can be shown that it is impossible to get a larger answer.
题意:给你一个n,让你找到a,b,使得a+b=n,并且s(a)+s(b)最大,s(123)=1+2+3,输出s(a)+s(b)
分析:我们很容易想到,当拆分的两个数中9的数量最多的时候,s(a)+s(b)最大,例如35=29+6=19+16=9+26=17+18,我们发现他们的s(a)+s(b)都等于17;
又比如 10000000000,我们可以拆成 10000000000=9999999999+1=9999999998+2...,他们的s(a)+s(b)都等于91
所以我们可以从最高位拆分,比如23456=19999+3457,100=99+1,123=99+24这种形式,这时获得的9是最多的,s(a)+s(b)也是最大的
#include<cstdio>
int main()
{
long long n;
while(~scanf("%lld",&n))
{
long long t,tt=;
t=n;
while(t>)
{
t/=;
tt*=;
}//找到最高位
long long ans1=t*tt-;//第一部分
long long ans2=n-ans1;第二部分
int sum=;
while(ans1)//求第一部分每个数字的和
{
sum+=ans1%;
ans1/=;
}
while(ans2)//求第二部分每个数字的和
{
sum+=ans2%;
ans2/=;
}
printf("%d\n",sum);
}
return ;
}
D-codeforces712c
Description
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Sample Input
6 3
4
8 5
3
22 4
6
Hint
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do
.
In the second sample test, Memory can do
.
In the third sample test, Memory can do: 
.
题意:给你一个x,y,让你从边长为y的等边三角形变到边长为x的等边三角形,一次只能改动一条边的大小,问你最少需要改动多少次
分析:改动一条边的前提是,改动这条边后,这三条边还是能组成一个三角形,满足a+b>c,a-b<c。一开始三边为(a,b,c)并且a=b=c,,将最小的那条边变为另外那两条边相加再减一,(a,b,a+b-1),满足a+b>c&&a-b<c,依次改动下去...直到某一条边将大于等于x,这时,三条边都处于小于x的状态,每条边只需要再改动一次即可形成边长为x的等边三角形
注意: 要开long long
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
int x,y;
while(~scanf("%d %d",&x,&y))
{
int ans=,flag=;
int t=y,k=y;//t,tt表示每一轮的三角形中最大的边和第二大的边
while()
{
if(t+k-<x)//每改动一条边次数加1
ans++;
else//当某条边将要大于等于x的时候就退出
break;
if(flag==)
{
t+=k-;
flag=;
}
else
{
k+=t-;
flag=;
} }
printf("%d\n",ans+);//最后每一条边再改动一次就能形成边长为x的等边三角形
}
return ;
}
E-codeforces 712B
Description
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion:
- An 'L' indicates he should move one unit left.
- An 'R' indicates he should move one unit right.
- A 'U' indicates he should move one unit up.
- A 'D' indicates he should move one unit down.
But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in s with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string.
Input
The first and only line contains the string s (1 ≤ |s| ≤ 100 000) — the instructions Memory is given.
Output
If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.
Sample Input
RRU
-1
UDUR
1
RUUR
2
Hint
In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.
In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change s to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.
题意:给你一个字符串s,其中的‘U’代表上,‘D’代表下,‘L’代表左,‘R’代表右,每次只能改变一个字符,问你最少需要改动多少次,memory能回到起点,输出最小的改动次数,若不能回到起点则输出-1。
分析:当字符串长度为奇数时,一定不能回到起点。
当字符串长度为偶数时,统计字符串中u,d,l,r的数量,需要改动的次数为|(u-d)/2|+|(l-r)/2|,需要注意的是,当u-d与l-r同时为奇数时,会少算一次改动的次数,加上就好了。
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
char s[];
while(~scanf("%s",s))
{
int k;
k=strlen(s);
if(k%!=)
printf("-1\n");
else
{
int u=,d=,l=,r=;
for(int i=; i<k; i++)
{
if(s[i]=='U')
u++;
else if(s[i]=='D')
d++;
else if(s[i]=='L')
l++;
else if(s[i]=='R')
r++;
}
int sum=;
sum+=abs(u-d)/+abs(l-r)/;
if((u-d)%!=&&(l-r)%!=)
sum++;
printf("%d\n",sum);
}
}
return ;
}
2018SDIBT_国庆个人第五场的更多相关文章
- 2018SDIBT_国庆个人第七场
A - Complete the Word(暴力) Description ZS the Coder loves to read the dictionary. He thinks that a wo ...
- 2018SDIBT_国庆个人第六场
A - A codeforces 714A Description Today an outstanding event is going to happen in the forest — hedg ...
- 2018SDIBT_国庆个人第四场
A - A 这题很巧妙啊,前两天刚好做过,而且就在博客里 Little C Loves 3 I time limit per test 1 second memory limit per test ...
- 2018SDIBT_国庆个人第三场
A - A CodeForces - 1042A There are nn benches in the Berland Central park. It is known that aiai peo ...
- HDU(4528),BFS,2013腾讯编程马拉松初赛第五场(3月25日)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4528 小明系列故事——捉迷藏 Time Limit: 500/200 MS (Java/O ...
- noi.ac 第五场第六场
t1应该比较水所以我都没看 感觉从思路上来说都不难(比牛客网这可简单多了吧) 第五场 t2: 比较套路的dp f[i]表示考虑前i个数,第i个满足f[i]=i的最大个数 i能从j转移需要满足 j< ...
- # NOI.AC省选赛 第五场T1 子集,与&最大值
NOI.AC省选赛 第五场T1 A. Mas的童年 题目链接 http://noi.ac/problem/309 思路 0x00 \(n^2\)的暴力挺简单的. ans=max(ans,xor[j-1 ...
- NOI.AC NOIP模拟赛 第五场 游记
NOI.AC NOIP模拟赛 第五场 游记 count 题目大意: 长度为\(n+1(n\le10^5)\)的序列\(A\),其中的每个数都是不大于\(n\)的正整数,且\(n\)以内每个正整数至少出 ...
- 牛客网暑期ACM多校训练营(第五场):F - take
链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...
随机推荐
- C# Socket的Send问题,阻塞线程
Socket sc = comm.connectSocket(ip, port, ReceiveMsg_fromPc); comm.sendSocketMsg16(sc,cmd); sc.Close( ...
- header头参数不能带下划线
header头参数不能带下划线:game_id是错误的
- mysql 8.0 错误The server requested authentication method unknown to the client
mysql 安装了最新版本8.0.11后创建用户并授权后,授权的用户连接数据库提示 The server requested authentication method unknown to the ...
- 俞敏洪:我创业24年感悟的3条CEO守则
转自:http://www.gamelook.com.cn/2017/10/306603 创业24年,他的创业经历被拍成了电影.在一次小范围聚会时,他说现实远比剧本要精彩.“如果让我一切从头开始,我会 ...
- C# 自己动手实现Spy++(一)
因为项目要用到获取其他程序的标题,就想到了用Spy++,但是它是一个工具,并没有C#的源代码,所以就想探索下他的原理,网上搜索了下spy++的源代码,找到了一篇:http://blog.csdn.ne ...
- Python开发之AJAX
一.概述 对于WEB应用程序:用户浏览器发送请求,服务器接收并处理请求,然后返回结果,往往返回就是字符串(HTML),浏览器将字符串(HTML)渲染并显示浏览器上. 1.传统的Web应用:一个简单操作 ...
- echarts.js应用之map
最近项目中用到了echarts.js中的map,我画了一个简版的案例,如下所示: 效果图: 主要代码如下: <!DOCTYPE html> <html lang="en&q ...
- 使用sqoop从mysql导入数据到hive
目录 前言 一.使用的导入命令 二.遇到的问题及解决 1. 用文本字段进行分区的问题 2. Hadoop历史服务器Hadoop JobHistory没开启的问题 3. 连接元数据存储数据库报错 4 ...
- <创新思维与实践>总结梳理
2017年12月3-4号 培训了两天的创新思维与实践,有时间要补充总结一下. ---todo
- [Unity插件]Lua行为树(七):行为树嵌套
在上一篇的基础上,可以测试下行为树的嵌套,所谓的行为树嵌套,就是在一棵行为树下的某一个分支,接入另一棵行为树. 以下面这棵行为树为例: TestBehaviorTree2.lua TestBehavi ...