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. 我优化了一下:jquery点击元素以外任意地方隐藏该元素的方法

    我优化了一下 $(document).bind('click', function (event) { var evt = event.srcElement ? event.srcElement : ...

  2. [UE4]Set Skeletal Mesh,在蓝图中设置骨骼模型

  3. [UE4]单机游戏改网络游戏,不完全清单

    把Actor的复制打开 中腰数据的复制打开,且只在服务器修改(比如角色属性血量) 需要同步的Actor,不在客户端Spawn 客户端的操作,先报告到服务器,服务器再广播到所有客户端 某些逻辑只在服务器 ...

  4. POJ3159 Candies

    #include <iostream> #include <queue> #include <cstring> #define maxn 30005 #define ...

  5. IDEA非sbt下spark开发

    创建非sbt的scala项目 引入spark的jar包 File->Project Structure->Libararies引用spark-assembly-1.5.2-hadoop2. ...

  6. 使用Mongo dump 将数据导入到hive

    概述:使用dump 方式将mongo数据导出,上传到hdfs,然后在hive中建立外部表. 1.     使用mongodump 将集合导出 mongodump --host=localhost:27 ...

  7. Nginx80端口转发+域名——实现IP+端口隐藏

    一.目的1.相信大家会遇到这样的问题:当一台服务器部署多个tomcat应用时,当我们访问tomcat时,需要在浏览器中输入服务器IP+端口号,这看起来非常的low. 二. 环境 1台服务服务器 假如I ...

  8. Centos下添加用户并赋权

    创建新用户 创建一个用户名为:linuxidc [root@localhost ~]# adduser linuxidc 为这个用户初始化密码,linux会判断密码复杂度,不过可以强行忽略: [roo ...

  9. 【转】【Web测试】Web测试点页面总结整理

    转自:http://blog.csdn.net/qq_30044187/article/details/52442518 1.页面链接检查: 测试每一个链接是否都有对应的页面,并且页面之前可以正确切换 ...

  10. return的一种用法:如果当前判断为true则跳出这个方法。

    package rom; import java.lang.*; /* * return的一种用法:如果当前判断为true则跳出这个方法. */ public class Xamle_5 { stat ...