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

Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
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

Input
35
Output
17
Input
10000000000
Output
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

Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
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 ab, 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

Input
RRU
Output
-1
Input
UDUR
Output
1
Input
RUUR
Output
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_国庆个人第五场的更多相关文章

  1. 2018SDIBT_国庆个人第七场

    A - Complete the Word(暴力) Description ZS the Coder loves to read the dictionary. He thinks that a wo ...

  2. 2018SDIBT_国庆个人第六场

    A - A codeforces 714A Description Today an outstanding event is going to happen in the forest — hedg ...

  3. 2018SDIBT_国庆个人第四场

    A - A  这题很巧妙啊,前两天刚好做过,而且就在博客里  Little C Loves 3 I time limit per test 1 second memory limit per test ...

  4. 2018SDIBT_国庆个人第三场

    A - A CodeForces - 1042A There are nn benches in the Berland Central park. It is known that aiai peo ...

  5. HDU(4528),BFS,2013腾讯编程马拉松初赛第五场(3月25日)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4528 小明系列故事——捉迷藏 Time Limit: 500/200 MS (Java/O ...

  6. noi.ac 第五场第六场

    t1应该比较水所以我都没看 感觉从思路上来说都不难(比牛客网这可简单多了吧) 第五场 t2: 比较套路的dp f[i]表示考虑前i个数,第i个满足f[i]=i的最大个数 i能从j转移需要满足 j< ...

  7. # NOI.AC省选赛 第五场T1 子集,与&最大值

    NOI.AC省选赛 第五场T1 A. Mas的童年 题目链接 http://noi.ac/problem/309 思路 0x00 \(n^2\)的暴力挺简单的. ans=max(ans,xor[j-1 ...

  8. NOI.AC NOIP模拟赛 第五场 游记

    NOI.AC NOIP模拟赛 第五场 游记 count 题目大意: 长度为\(n+1(n\le10^5)\)的序列\(A\),其中的每个数都是不大于\(n\)的正整数,且\(n\)以内每个正整数至少出 ...

  9. 牛客网暑期ACM多校训练营(第五场):F - take

    链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...

随机推荐

  1. 廖雪峰Java1-3流程控制-3条件判断

    1.if条件判断的格式 if (条件) { 代码块 } if (条件) { 代码块1 } else { 代码块2 } if (条件1) { 代码块1 } else if { 代码块2 } else { ...

  2. [UE4]Slot

    一.Slot是容器中子控件的一个属性,因此每个子控件的Slot属性值都可以不一样. 二.不同容器提供的Slot属性都不一样 三.Canvas Panel提供的Slot Anchors预设16种常见的样 ...

  3. [UE4]旋转小地图

    一.Canvas Panel的旋转原点是Render Transform——>Pivot,Pivot坐标的取值范围是0到1,左上角的pivot坐标是[0,0],右下角的pivot坐标是[1,1] ...

  4. [UE4]使用蓝图关闭对象的碰撞SetActorEnableCollision

    在一个人的身上创建多把枪的时候,由于枪与枪之间重贴会产生碰撞冲突,到时角色控制出现不正常(上下左右行走总是往一个方向移动),这些可以关闭枪支的碰撞:

  5. golang 反射应用(二)

    golang反射应用(二) package test import ( "reflect" "testing" ) //定义适配器 func TestRefle ...

  6. 成功设置open live writer

    mark一下,哈哈哈 https://www.cnblogs.com/chrisrockdl/

  7. RSA加密解密,String转PublicKey、PrivateKey;附Base64.JAR

    网络请求的数据需要加密,服务器给的他们那一套在Android一直报错,自己写了一个: package com.cc.common.util; import javax.crypto.Cipher; i ...

  8. MySQL安装,库的操作

    一 数据库管理软件的由来 基于我们之前所学,数据要想永久保存,都是保存于文件中,毫无疑问,一个文件仅仅只能存在于某一台机器上. 如果我们暂且忽略直接基于文件来存取数据的效率问题,并且假设程序所有的组件 ...

  9. @ResponseBody返回中文乱码

    1.在方法上修改编码 这种方式,需要对每个方法都进行配置. 2.修改springmvc的配置文件 同时注意,把这个配置写在扫描包的上面.

  10. Java之24种设计模式-UML-模型图解读

    Design Patterns 策略模式: 观察者模式: 经典单例模式: private static class AuthenticationHolder { private static fina ...