2020.10.16--vj个人赛补题
Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?
There are nn students living in a building, and for each of them the favorite drink aiai is known. So you know nn integers a1,a2,…,ana1,a2,…,an, where aiai (1≤ai≤k1≤ai≤k) is the type of the favorite drink of the ii-th student. The drink types are numbered from 11 to kk.
There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are kk types of drink sets, the jj-th type contains two portions of the drink jj. The available number of sets of each of the kktypes is infinite.
You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly ⌈n2⌉⌈n2⌉, where ⌈x⌉⌈x⌉ is xx rounded up.
After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if nn is odd then one portion will remain unused and the students' teacher will drink it.
What is the maximum number of students that can get their favorite drink if ⌈n2⌉⌈n2⌉ sets will be chosen optimally and students will distribute portions between themselves optimally?
Input
The first line of the input contains two integers nn and kk (1≤n,k≤10001≤n,k≤1000) — the number of students in the building and the number of different drinks.
The next nn lines contain student's favorite drinks. The ii-th line contains a single integer from 11 to kk — the type of the favorite drink of the ii-th student.
Output
Print exactly one integer — the maximum number of students that can get a favorite drink.
Examples
5 3
1
3
1
1
2
4
10 3
2
1
3
2
3
3
1
3
1
2
9
Note
In the first example, students could choose three sets with drinks 11, 11 and 22 (so they will have two sets with two drinks of the type 11 each and one set with two drinks of the type 22, so portions will be 1,1,1,1,2,21,1,1,1,2,2). This way all students except the second one will get their favorite drinks.
Another possible answer is sets with drinks 11, 22 and 33. In this case the portions will be 1,1,2,2,3,31,1,2,2,3,3. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with ai=1ai=1 (i.e. the first, the third or the fourth).
题意:有n个学生住在一栋楼里,每个人最喜欢的饮料ai是已知的。所以你知道n个整数a1 a2…an,其中ai(1≤ai≤k)是第i个学生最喜欢的饮料类型。饮料类型从1到k进行编号。
有无数种饮料。每一组包含两份相同的饮料,也就是说,有k种类型的饮料集,即第j种包含了两份饮料j,每一种类型的可用集的数量是无限的,
选出n/2种,x向上取最大,学生们收到这些套装后,他们将根据自己的选择分配他们的份额:每个学生将得到恰好一份。请注意,如果n是奇数,那么有一部分将不使用,学生的老师将喝它。
问学生们将得到他们最喜欢的饮料的最大人数是多少?
输入
输入的第一行包含两个整数n和k(1≤n,k≤1000)-建筑物内的学生人数和不同饮料的数量。
接下来的n行包含学生最喜欢的饮料。第i行包含一个从1到k的整数——第i个学生最喜欢的饮料的类型。
输出
准确地打印一个整数-可以得到最喜欢的饮料的学生的最大人数。
题解: 将每种类型的个数用数组 b[] 记录下来,设一变量ct=0,用于记载最大人数,因为只能选n/2个类型,每个类型包含两种相同的饮料,所以当数组元素大于等于2时,
b[i]-=2,ct+=2,(n/2)--;直至b[i]<2或m<=0
#include<bits/stdc++.h>
using namespace std;
const int maxn=1010;
int main()
{
int n,k,i,j;
cin>>n>>k;
int m=(n+1)/2;
int ct=0;
int b[maxn];
memset(b,0,sizeof(b));
while(n--)
{
int a;
cin>>a;
++b[a];
}
sort(b,b+k+1,greater<int>());
for(i=0;i<k;i++)
{
while(b[i]>=2&&m>0)
{
b[i]-=2;
--m;
ct+=2;
}
}
cout<<ct+m<<endl;
}
Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia.
For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs nn actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options:
- the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by 11;
- the second option is to put candies in the box. In this case, Alya will put 11 more candy, than she put in the previous time.
Thus, if the box is empty, then it can only use the second option.
For example, one possible sequence of Alya's actions look as follows:
- put one candy into the box;
- put two candies into the box;
- eat one candy from the box;
- eat one candy from the box;
- put three candies into the box;
- eat one candy from the box;
- put four candies into the box;
- eat one candy from the box;
- put five candies into the box;
This way she will perform 99 actions, the number of candies at the end will be 1111, while Alya will eat 44candies in total.
You know the total number of actions nn and the number of candies at the end kk. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given nn and kk the answer always exists.
Please note, that during an action of the first option, Alya takes out and eats exactly one candy.
Input
The first line contains two integers nn and kk (1≤n≤1091≤n≤109; 0≤k≤1090≤k≤109) — the total number of moves and the number of candies in the box at the end.
It's guaranteed, that for the given nn and kk the answer exists.
Output
Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data.
Examples
1 1
0
9 11
4
5 0
3
3 2
1
Note
In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate 00 candies.
In the second example the possible sequence of Alya's actions looks as follows:
- put 11 candy,
- put 22 candies,
- eat a candy,
- eat a candy,
- put 33 candies,
- eat a candy,
- put 44 candies,
- eat a candy,
- put 55 candies.
This way, she will make exactly n=9n=9 actions and in the end the box will contain 1+2−1−1+3−1+4−1+5=111+2−1−1+3−1+4−1+5=11 candies. The answer is 44, since she ate 44 candies in total.
大体题意:为了比赛,Alya在盒子里放了糖果,作为获胜者的奖品。为了做到这一点,她做了n个动作。第一个动作是放一颗糖到盒子里。对于剩下的每一步,她可以从两个选项中选择:第一个选项,如果盒子里至少有一颗糖,那就是拿出一颗糖吃了。这样盒子里糖果的数量减少了1;第二种选择是在盒子里放糖果。在这种情况下,Alya会比之前多放1个糖果。因此,如果盒子是空的,那么她只能使用第二个选项。
已知有n次行动和最终剩下k个糖果,问Alya吃了几个糖果:
题解:列公式计算--设吃了x个糖果,向盒子里放了y次,根据等差公式,y符合:
y+(y*(y-1))/2,即总共放了多少颗糖果;
所以可得到:1. x+y=n ; 2. y+(y*(y-1))/2-x=k;
两式相加得 :y*y+3*y=2*(n+k) 求出y,所以x=n-y;
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll n,k;
scanf("%lld %lld",&n,&k);
ll i;
for(i=0; ;i++)
{
if((i*i+3*i)==(2*(n+k)))
{
cout<<n-i<<endl;
break;
}
}
}
B - B
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
- letters on positions from A in the string are all distinct and lowercase;
- there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
11
aaaaBaabAbA
2
12
zACaAbbaazzC
3
3
ABC
0
Note
In the first example the desired positions might be 6 and 8or 7 and 8. Positions 6 and 7 contain letters 'a', position 8contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
题意:求连续的小写字母中不同字母的最大数量
题解:运用set,set可以去掉重复的字母,存到一个字符串数组里,同时记录下长度,找到最长的输出
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
char s[1000];
int n,ct=0;
set<char>b;
cin>>n>>s;
for(int i=0;i<n;i++)
{
if(s[i]>='a'&&s[i]<='z')
{
b.insert(s[i]);
}
else{
if(ct<b.size())ct=b.size();
b.clear();
}
}
if(ct<b.size)ct=b.size();
b.clear();
cout<<ct<<endl;
}
F - F
On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.
Seating in the class looks like a rectangle, where n rows with m pupils in each.
The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...
The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.
During the lesson the teacher managed to ask exactly kquestions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values:
- the maximum number of questions a particular pupil is asked,
- the minimum number of questions a particular pupil is asked,
- how many times the teacher asked Sergei.
If there is only one row in the class, then the teacher always asks children from this row.
Input
The first and the only line contains five integers n, m, k, xand y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).
Output
Print three integers:
- the maximum number of questions a particular pupil is asked,
- the minimum number of questions a particular pupil is asked,
- how many times the teacher asked Sergei.
Examples
1 3 8 1 1
3 2 3
4 2 9 4 2
2 1 1
5 5 25 4 3
1 1 1
100 100 1000000000000000000 100 100
101010101010101 50505050505051 50505050505051
Note
The order of asking pupils in the first test:
- the pupil from the first row who seats at the first table, it means it is Sergei;
- the pupil from the first row who seats at the second table;
- the pupil from the first row who seats at the third table;
- the pupil from the first row who seats at the first table, it means it is Sergei;
- the pupil from the first row who seats at the second table;
- the pupil from the first row who seats at the third table;
- the pupil from the first row who seats at the first table, it means it is Sergei;
- the pupil from the first row who seats at the second table;
The order of asking pupils in the second test:
- the pupil from the first row who seats at the first table;
- the pupil from the first row who seats at the second table;
- the pupil from the second row who seats at the first table;
- the pupil from the second row who seats at the second table;
- the pupil from the third row who seats at the first table;
- the pupil from the third row who seats at the second table;
- the pupil from the fourth row who seats at the first table;
- the pupil from the fourth row who seats at the second table, it means it is Sergei;
- the pupil from the third row who seats at the first table;
题意是老师点名的顺序是从第一排点到最后一排再逆序点到第一排,每排都是从第一个点到最后一个,让你求点名最多的点了多少次,点名最少的点了多少次,和一个指定的位置点了多少次。
运用到了dp,但还不会用(来自大佬的代码如下)
思路:
1、首先观察到N,M并不大,那么我们考虑先处理掉提问次数剩余<N*M的时候,那么剩下的部分我们只要暴力涂提问次数即可。
2、提问一轮(从1走出去再回到1)是按照1.2.3.4....n.n-1.....2来的。
那么就是第一行和最后一行只涂了一次(提问了一次);
中间的所有行都涂了两次。
那么每一轮提问都需要涂:(2*n-2)*m次。
那么一共就涂了K/((2*n-2)*m)个整数次。
那么剩余部分就是K%((2*n-2)*m)。
剩余部分暴力涂上去即可。
查询也是暴力查询的。
3、注意N==1的时候需要特判。
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define ll __int64
ll ans[150][150];
ll n,m,k,x,y;
int main()
{
while(~scanf("%I64d%I64d%I64d%I64d%I64d",&n,&m,&k,&x,&y))
{
if(n==1)
{
ll all=k/(n*m);
ll yu=k%(n*m);
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
if(yu>=1)
ans[i][j]=all+1;
else ans[i][j]=all;
yu--;
}
}
ll maxn=0;
ll minn=2000000000000000000;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
maxn=max(maxn,ans[i][j]);
minn=min(minn,ans[i][j]);
}
}
printf("%I64d %I64d %I64d\n",maxn,minn,ans[x][y]);
}
else
{
ll all=k/((2*n-2)*m);
ll yu=k%((2*n-2)*m);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(i==1||i==n)ans[i][j]=all;
else ans[i][j]=all*2;
}
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
if(yu>=1)
ans[i][j]++;
yu--;
}
}
for(int i=n-1; i>=2; i--)
{
for(int j=1; j<=m; j++)
{
if(yu>=1)
ans[i][j]++;
yu--;
}
}
ll maxn=0;
ll minn=2000000000000000000;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
maxn=max(maxn,ans[i][j]);
minn=min(minn,ans[i][j]);
}
}
printf("%I64d %I64d %I64d\n",maxn,minn,ans[x][y]);
}
}
}
2020.10.16--vj个人赛补题的更多相关文章
- 2020.10.17-pta天梯练习赛补题
7-5敲笨钟 微博上有个自称"大笨钟V"的家伙,每天敲钟催促码农们爱惜身体早点睡觉.为了增加敲钟的趣味性,还会糟改几句古诗词.其糟改的方法为:去网上搜寻压"ong&quo ...
- 2020.10.30--vj个人赛补题
D - D CodeForces - 743A Vladik is a competitive programmer. This year he is going to win the Interna ...
- 2020.10.9--vj个人赛补题
B - A Tide of Riverscape 题意:给出一组字符串,由'0','1',' . '组成,' . '可以换成 0或1,判断第 i 个和第 i+p 个字符是否可以不相等,如果可以则输出 ...
- 2020.10.23-vj个人赛补题
B - B Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consistin ...
- QFNU-ACM 2020.04.05个人赛补题
A.CodeForces-124A (简单数学题) #include<cstdio> #include<algorithm> #include<iostream> ...
- 2020.12.3--vj个人赛补题
A Vasya studies music.He has learned lots of interesting stuff. For example, he knows that there are ...
- 2020.12.20-Codeforces Round #105补题
B - Escape The princess is going to escape the dragon's cave, and she needs to plan it carefully. Th ...
- 2020.11.14-pta天梯练习赛补题
7-7 矩阵A乘以B 给定两个矩阵A和B,要求你计算它们的乘积矩阵AB.需要注意的是,只有规模匹配的矩阵才可以相乘.即若A有Ra行.Ca列,B有Rb行.Cb列,则只有Ca ...
- 牛客 2020.10.20 TG 前两题
T1 GCD 数学水题... 对于每个数,如果这个数有两个及以上的质因数的话,它所有除 \(1\) 之外的因数求 \(GCD\) 的值一定为 \(1\).那么判断是否是质数或质数的次方即可(质数除 \ ...
随机推荐
- android http get
Executors.newSingleThreadExecutor().execute{ val uri = "https://www.cnblogs.com/hangj" val ...
- 被面试官问懵:TCP 四次挥手收到乱序的 FIN 包会如何处理?
摘要:收到个读者的问题,他在面试的时候,被搞懵了,因为面试官问了他这么一个网络问题. 本文分享自华为云社区<TCP 四次挥手收到乱序的 FIN 包会如何处理?>,作者:小林coding . ...
- Python - 面向对象编程 - 三大特性之封装
简单介绍封装 封装是面向对象编程的一大特点 封装可以被认为是一个保护屏障,防止该类的属性.方法和数据结构被外部随意访问 要访问该类的属性.私有方法.数据结构,必须由指定的方法控制访问 深入理解封装 在 ...
- 菜狗、《灵笼》、《时光代理人》,重新审视Z世代的电商逻辑
来源:懂懂笔记 B站还有多少潜力可以挖掘? 虽然B站的最新财报依然还是亏损,但同时也让人看到更多的可能性. 从财报数据的亮点来看,一是营收增长,B站二季度营收为44.95亿元,同比增长72%.营收上B ...
- python库--pandas--DataFrame
转换 索引,迭代 运算符 功能应用,分组及窗口 计算/描述统计 重新索引/选择/标签操作 缺失数据处理 形状变换/排序/转置 组合/加入/合并 时间序列相关 ...
- Python脚本运行出现语法错误:IndentationError:unexpected indent
对于py来说典型错误就是缩进,,烦不胜烦,整理一下解决方法:一个python脚本,本来都运行好好的,然后写了几行代码,而且也都确保每行都对齐了,但是运行的时候,却出现语法错误: Indentation ...
- python爬取疫情数据存入MySQL数据库
import requests from bs4 import BeautifulSoup import json import time from pymysql import * def mes( ...
- 密码学系列之:Argon2加密算法详解
目录 简介 密钥推导函数key derivation function Password Hashing Competition Argon2算法 Argon2的输入参数 处理流程 简介 Argon2 ...
- js不记录某个url链接历史访问,返回时不返回该链接
(function(){ var fnUrlReplace = function (eleLink) { if (!eleLink) { return; } var href = eleLink.hr ...
- javascript 继承 inheritance prototype
* Rectangle继承Shape function Shape() { this.x = 0; this.y = 0; } Shape.prototype.move = function(x, ...