Codeforces Round #561 (Div. 2)ABC

2023-11-16

三个题,各位大佬别喷我,我很菜
A Silent Classroom
There are n students in the first grade of Nlogonia high school. The principal wishes to split the students into two classrooms (each student must be in exactly one of the classrooms). Two distinct students whose name starts with the same letter will be chatty if they are put in the same classroom (because they must have a lot in common). Let x be the number of such pairs of students in a split. Pairs (a,b) and (b,a) are the same and counted only once.

For example, if there are 6 students: “olivia”, “jacob”, “tanya”, “jack”, “oliver” and “jessica”, then:

splitting into two classrooms (“jack”, “jacob”, “jessica”, “tanya”) and (“olivia”, “oliver”) will give x=4 (3 chatting pairs in the first classroom, 1 chatting pair in the second classroom),
splitting into two classrooms (“jack”, “tanya”, “olivia”) and (“jessica”, “oliver”, “jacob”) will give x=1 (0 chatting pairs in the first classroom, 1 chatting pair in the second classroom).
You are given the list of the n names. What is the minimum x we can obtain by splitting the students into classrooms?

Note that it is valid to place all of the students in one of the classrooms, leaving the other one empty.

Input
The first line contains a single integer n (1≤n≤100) — the number of students.

After this n lines follow.

The i-th line contains the name of the i-th student.

It is guaranteed each name is a string of lowercase English letters of length at most 20. Note that multiple students may share the same name.

Output
The output must consist of a single integer x — the minimum possible number of chatty pairs.

Examples
Input
4
jorge
jose
oscar
jerry
Output
1
Input
7
kambei
gorobei
shichiroji
kyuzo
heihachi
katsushiro
kikuchiyo
Output
2
Input
5
mike
mike
mike
mike
mike
Output
4
Note
In the first sample the minimum number of pairs is 1. This can be achieved, for example, by putting everyone except jose in one classroom, and jose in the other, so jorge and jerry form the only chatty pair.

In the second sample the minimum number of pairs is 2. This can be achieved, for example, by putting kambei, gorobei, shichiroji and kyuzo in one room and putting heihachi, katsushiro and kikuchiyo in the other room. In this case the two pairs are kambei and kyuzo, and katsushiro and kikuchiyo.

In the third sample the minimum number of pairs is 4. This can be achieved by placing three of the students named mike in one classroom and the other two students in another classroom. Thus there will be three chatty pairs in one classroom and one chatty pair in the other classroom.
只有首字母相同的才会说话,问最小有多少个人能互相说话。
最小的时候就是一个房间里有一半人。。。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int n;
map<char,int>mp;
string s;
 
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		int cnt=1;
		mp.clear();
		for(int i=0;i<n;i++)
		{
			cin>>s;
			mp[s[0]]++;
		}
		int sum=0;
		for(map<char,int> ::iterator it=mp.begin();it!=mp.end();it++)
		{
			ll x=it->second/2;
			ll y;
			if(x*2!=it->second) y=x+1;
			else y=x;
			sum+=(x)*(x-1)/2+y*(y-1)/2;
		}
		cout<<sum<<endl;
	}
}

B All the Vowels Please
Tom loves vowels, and he likes long words with many vowels. His favorite words are vowelly words. We say a word of length k is vowelly if there are positive integers n and m such that n⋅m=k and when the word is written by using n rows and m columns (the first row is filled first, then the second and so on, with each row filled from left to right), every vowel of the English alphabet appears at least once in every row and every column.

You are given an integer k and you must either print a vowelly word of length k or print −1 if no such word exists.

In this problem the vowels of the English alphabet are ‘a’, ‘e’, ‘i’, ‘o’ ,‘u’.

Input
Input consists of a single line containing the integer k (1≤k≤104) — the required length.

Output
The output must consist of a single line, consisting of a vowelly word of length k consisting of lowercase English letters if it exists or −1 if it does not.

If there are multiple possible words, you may output any of them.

Examples
Input
7
Output
-1
Input
36
Output
agoeuioaeiruuimaeoieauoweouoiaouimae
Note
In the second example, the word “agoeuioaeiruuimaeoieauoweouoiaouimae” can be arranged into the following 6×6 grid:
在这里插入图片描述

It is easy to verify that every row and every column contain all the vowels.
构造,每一行每一列都要有5个元音字母,嘤嘤嘤,一开始理解错了wa了几发
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;

int n;

int main()
{
	while(~scanf("%d",&n))
	{
		int pos;
		int flag=0;
		for(int i=5;i<=sqrt(n);i++)
		{
			if(n%i==0)
			{
				if(i>=5&&n/i>=5)
				{
					flag=1;
					pos=i;
					break;
				}
			}
		}
		if(flag==0)
		{
			cout<<"-1"<<endl;
			continue;
		}
		string s[6];
		s[1]="aeiou";
		s[2]="eaoui";
		s[3]="iuaeo";
		s[4]="oiuae";
		s[5]="uoeia";
		for(int i=1;i<=n/pos;i++)
		{
			cout<<s[(i%5)?i%5:5];
			for(int j=0;j<pos-5;j++)
			{
				if(j==0) cout<<s[(i%5)?i%5:5][1];
				else cout<<s[(i%5)?i%5:5][(j%4)+1];
			}
			//cout<<endl;
		}
		cout<<endl;
	}
}
/*
aoeui
oaeiu
uiaeo
ieuoweouoiaouimae
*/

C A Tale of Two Lands
The legend of the foundation of Vectorland talks of two integers x and y. Centuries ago, the array king placed two markers at points |x| and |y| on the number line and conquered all the land in between (including the endpoints), which he declared to be Arrayland. Many years later, the vector king placed markers at points |x−y| and |x+y| and conquered all the land in between (including the endpoints), which he declared to be Vectorland. He did so in such a way that the land of Arrayland was completely inside (including the endpoints) the land of Vectorland.

Here |z| denotes the absolute value of z.

Now, Jose is stuck on a question of his history exam: “What are the values of x and y?” Jose doesn’t know the answer, but he believes he has narrowed the possible answers down to n integers a1,a2,…,an. Now, he wants to know the number of unordered pairs formed by two different elements from these n integers such that the legend could be true if x and y were equal to these two values. Note that it is possible that Jose is wrong, and that no pairs could possibly make the legend true.

Input
The first line contains a single integer n (2≤n≤2⋅105) — the number of choices.

The second line contains n pairwise distinct integers a1,a2,…,an (−109≤ai≤109) — the choices Jose is considering.

Output
Print a single integer number — the number of unordered pairs {x,y} formed by different numbers from Jose’s choices that could make the legend true.

Examples
Input
3
2 5 -3
Output
2
Input
2
3 6
Output
1
Note
Consider the first sample. For the pair {2,5}, the situation looks as follows, with the Arrayland markers at |2|=2 and |5|=5, while the Vectorland markers are located at |2−5|=3 and |2+5|=7:
在这里插入图片描述

The legend is not true in this case, because the interval [2,3] is not conquered by Vectorland. For the pair {5,−3} the situation looks as follows, with Arrayland consisting of the interval [3,5] and Vectorland consisting of the interval [2,8]:
在这里插入图片描述

As Vectorland completely contains Arrayland, the legend is true. It can also be shown that the legend is true for the pair {2,−3}, for a total of two pairs.

In the second sample, the only pair is {3,6}, and the situation looks as follows:
在这里插入图片描述

Note that even though Arrayland and Vectorland share 3 as endpoint, we still consider Arrayland to be completely inside of Vectorland.

咋说嘞,因为最后都是绝对值,都是正数。如果x<y,那么最后的式子就可以化为y-x<x<y<y+x,只有y-x<x这个式子需要判定条件,就是y<2*x。这样的话,我们给数组排个序,二分去找y,最后把结果加起来就好了。
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#define ll long long
using namespace std;

const int maxx=2e5+100;
ll a[maxx];
int n;

int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=0;i<n;i++)
		{
			scanf("%I64d",&a[i]);
			a[i]=abs(a[i]);
			//s.insert(abs(a[i]));
		}
		int cnt=0;
		//for(set<int> ::iterator it=s.begin();it!=s.end();it++) a[cnt++]=*it;
		sort(a,a+n);
		
		ll sum=0;
		for(int i=0;i<n;i++)
		{
			int pos=upper_bound(a,a+n,a[i]*2ll)-a;
			sum+=pos-i-1;
		}
		cout<<sum<<endl;
	}
}

努力加油a啊,(o)/~

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Codeforces Round #561 (Div. 2)ABC 的相关文章

随机推荐

  • 祝大家新年快乐

    好久没有更新文章了 说忙 这借口用化掉了 2022就要来了 祝大家新的一年一切都好 还是要立个flag 2022争取写完一套uniapp微信小程序开发系列文章吧 希望到时候大家能喜欢
  • Xenserver命令大全

    一 监控检查类xentop 查看XenServer与VM的资源使用情况xsconsole 进入XenServer管理面板 查看网卡 IP 系统版本 系统时间 硬件信息等 xe task list 查看XenServer临时任务进程servi
  • c++中rand()函数每次执行的结果都是一样的吗

    问题 include
  • 服务器硬盘接口图文观赏

    现在服务器上采用的硬盘接口技术主要有两种 SATA和SCSI 使用SAS硬盘的产品目前也已经上市 当然还有高端的光纤硬盘 其中前两种是最常见的 下面我们就SATA SCSI SAS等接口技术作简单介绍 SATA SATA Serial Ad
  • java类中获取ServletContext的方法

    在项目中遇到这样一个问题 需要在没有web请求的java普通类中 获取ServletContext 那么该怎么获取呢 答案就是通过ContextLoader类 WebApplicationContext webAc ContextLoade
  • 【华为OD机试 2023】 匿名信(C++ Java JavaScript Python)

    华为od机试题库 华为OD机试2022 2023 C Java JS Py https blog csdn net banxia frontend category 12225173 html 华为OD机试2023最新题库 更新中 C Ja
  • NHibernet Unable to locate persister for the entity

    第一 xml文件必须为 hbm xml 第二 设置xml文件为嵌入的资源 用鼠标点击右键 然后生成操作里 选择嵌入的资源即可解决 https www cnblogs com lyj 转载于 https www cnblogs com xia
  • SSD预测错误调试:RuntimeError: index_select(): functions with out=... arguments don‘t support automatic dif

    一 错误 运行SSD pytorch版本时 运行test py时 遇到这种错误 RuntimeError index select functions with out arguments don t support automatic d
  • Kafka面试必问几个概念 与 使用场景

    介绍下我写的这个kafka项目 里面做了详细的配置注释已经代码的demo 可供大家学习 项目 地址 springboot kafka集群项目实战 kafka集群批量消费数据去重和一致性 kafka的几个重要概念 接下来围绕下面几个概念来进行
  • 运放中接电容的作用

    运放概述 案例讲解 运算分析 一 基本概念 反向放大器 优点 两个输入端电位始终近似为零 同相端接地 反相端虚地 只有差模信号 抗干扰能力强 缺点 输入阻抗很小 等于信号到输入端的串联电阻的阻值 同相放大器 优点 输入阻抗和运放的输入阻抗相
  • 《JavaScript高级程序设计(第四版)》红宝书学习笔记(2)(第四章:变量、作用域与内存)

    个人对第四版红宝书的学习笔记 不适合小白阅读 这是part2 持续更新 其他章节笔记看我主页 记 的表示是ES6新增的知识点 记 表示包含新知识点 第四章 变量 作用域与内存 4 1 原始值与引用值 ECMAScript变量可以包含两种不同
  • C获取linux系统环境变量方法(Environment Variables)

    主要有三种方法 都很简单 1 一个单纯c语言获取的方式 span style font family none font size 14px include span
  • Java系列8—对象创建的内存分配和构造方法

    对象的创建 类和对象的区别 面向对象 java语言的核心机制 最重要的内容 java语言的特色 面向过程和面向对象的区别 面向过程 主要关注点是 实现的具体过程 因果关系 面向对象 主要关注对象 独立体 能完成哪些功能 优点 耦合度低 扩展
  • 态势感知(SIP)

    SIP态势感知 一 SIP态势感知概述 1 业界标准 数据来源 gt 智能分析 gt 安全可视 gt 协同响应 通过日志采集探针和流量传感器分别进行不同系统日志和流量日志的采集和处理任务 通过对海量数据进行多维度快速 自动化的关联分析发现本
  • 跨框架解决方案-Mitosis【问题与局限】

    不要定义与状态属性同名的变量 async方法不能定义在state内 函数不能通过引用直接传递给JSX回调函数 可以在回调函数中定义一个匿名函数 不能将 params 分配给 state 不能将函数输出分配给 state state不能被解构
  • dart 相关资源收集

    百丈高楼平地起 要想写好flutter 必先学号dart 资源 给 Android 开发者的 Dart 教程 学好 Dart 才能玩转 Flutter
  • ms-repeat 数据渲染后触发事件

    ms repeat 数据渲染后触发 data repeat rendered 例子 div class timebox h3 el year 年 el month 月 h3 ul li li ul div
  • MVC设计思想

    1 MVC思想的说明 经典MVC模式中 M是指业务模型 V是指用户界面 C则是控制器 使用MVC的目的是将M和V的实现代码分离 从而使同一个程序可以使用不同的表现形式 其中 View的定义比较清晰 就是用户界面 M model 业务模型 V
  • 24个笔画顺序表_语文老师整理:560个小学常用汉字笔画笔顺表!小学阶段多练习...

    今天给大家分享的是资深语文老师整理的学习资料 560个小学常用汉字笔画笔顺表 家里有小学生的家长 建议帮孩子存好 小学阶段多练习 不仅对语文学习的提高有帮助 还能培养孩子的语文素养 在小学语文的学习中 汉字是最基础的知识点 孩子在学习语文的
  • Codeforces Round #561 (Div. 2)ABC

    三个题 各位大佬别喷我 我很菜 A Silent Classroom There are n students in the first grade of Nlogonia high school The principal wishes