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 ...
随机推荐
- 关于Strategy和State设计模式
之前,我在描述我所采用的设计模式时,一直在Strategy和State之间犹豫,略微有些拿捏不准,说哪种设计模式好.结果到最后,会根据自己所想,觉得是State就是State,觉得Strategy就是 ...
- [UE4]寻找敌人
- [UE4]装饰器:Blackboard(装饰器的一种,不是黑板)
装饰器Blackboard可以检查黑板的值是否满足期望的条件: 添加“Blackboard装饰器”:在组合或者任务节点上右键“添加装饰器...”,跟普通装饰器一样. Notify Observer:通 ...
- vue的坑
1. (vue2.x以上,1.x没有问题)vue和jq一起使用的冲突:在使用了v-bind: class的元素上,当vue和jq都需要增改class时,用jq加的属性可能无效. 原因:当数据的布尔值改 ...
- vue 要点
一: 1. 如果在实例创建之后添加新的属性到实例上,它不会触发视图更新. 2. v-show 的元素会始终渲染并保持在 DOM 中.v-show 是简单的切换元素的 CSS 属性 display.
- mysql:视图,触发器,事务,存储过程,函数。
一 视图 1 什么是视图:视图其实就是通过查询得到一张表并且保存下来,就是一张虚拟的表,并非真实存在,比如我们将两个表在终端通过(inner join)内链接起来,那么我们得到的这个表就叫做视图,其 ...
- springboot中JPA的应用
1.JPA JPA(Java Persistence API)是Sun官方提出的Java持久化规范.它为Java开发人员提供了一种对象/关联映射工具来管理Java应用中的关系数据.他的出现主要是为了简 ...
- Python : 什么是*args和**kwargs[转载]
例子 def foo(*args, **kwargs):print 'args = ', argsprint 'kwargs = ', kwargsprint '------------------- ...
- promise请求数据用法
Promise简介 Promise 是异步编程的一种解决方案,比传统的解决方案–回调函数和事件--更合理和更强大.ES6将其写进了语言标准,统一了语法,里面保存着某个未来才回结束的事件(通常是一个异步 ...
- tornado-cookies+pycket 验证
1.pip install pycket pip install redis 2.config settings = dict( debug=True, template_path='template ...