首页 > 其他分享 >Codeforces Beta Round #42 (Div. 2)-C. Lucky Tickets

Codeforces Beta Round #42 (Div. 2)-C. Lucky Tickets

时间:2023-06-12 17:35:09浏览次数:50  
标签:Tickets Vasya number tickets 42 Lucky lucky pieces he


原题链接


C. Lucky Tickets



time limit per test



memory limit per test



input



output



Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid also threw part of the pieces away. Having seen this, Vasya got terrified but still tried to restore the collection. He chose several piece pairs and glued each pair together so that each pair formed a lucky ticket. The rest of the pieces Vasya threw away reluctantly. Thus, after the gluing of the 2t pieces he ended up with t

When Leonid tore the tickets in two pieces, one piece contained the first several letters of his number and the second piece contained the rest.

Vasya can glue every pair of pieces in any way he likes, but it is important that he gets a lucky ticket in the end. For example, pieces 123and 99 can be glued in two ways: 12399 and 99123.

What maximum number of tickets could Vasya get after that?



Input



The first line contains integer n (1 ≤ n ≤ 104) — the number of pieces. The second line contains n space-separated numbers ai(1 ≤ ai ≤ 108) — the numbers on the pieces. Vasya can only glue the pieces in pairs. Even if the number of a piece is already lucky, Vasya should glue the piece with some other one for it to count as lucky. Vasya does not have to use all the pieces. The numbers on the pieces an on the resulting tickets may coincide.



Output



Print the single number — the maximum number of lucky tickets that will be able to be restored. Don't forget that every lucky ticket is made of exactly two pieces glued together.



Examples



input



3
123 123 99



output



1



input



6
1 1 1 23 10 3



output



1







把所有的数字对3取模,分别记录0, 1, 2的个数为h0, h1, h2, 那么说有h0个数已经是三的倍数那么他们两两组合形成h0/2张卡片,取模结果为1的有h1张,结果为2的有h2张,它们能形成min(h1, h2)张卡片

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

int main(){
	
	int n, a;
	int k0 = 0, k1 = 0, k2 = 0;
	
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &a);
	    if(a % 3 == 0)
	     k0++;
	    else if(a % 3 == 1)
	     k1++;
	    else
	     k2++;
	}
	printf("%d\n", k0 / 2 + min(k1, k2));
	
	return 0;
}




标签:Tickets,Vasya,number,tickets,42,Lucky,lucky,pieces,he
From: https://blog.51cto.com/u_16158872/6464269

相关文章

  • LightOJ 1422 Halloween Costumes (区间DP)
    题意:你要连续去很多个舞会,给出n个舞会你需要穿的衣服的编号,一旦脱下就不能再穿,但是可以一件套一件,问最少需要准备多少件衣服。思路:区间DP,令dp[i][j]为第i到第j天需要的衣服,那么对于第i天,如果考虑后面没有和它重复的话,那么dp[i][j]=dp[i+1][j]+1,如果存在某一天a[i]==a[k],dp[i][j]=......
  • P1425 小鱼的游泳时间
    小鱼的游泳时间题目描述伦敦奥运会要到了,小鱼在拼命练习游泳准备参加游泳比赛,可怜的小鱼并不知道鱼类是不能参加人类的奥运会的。这一天,小鱼给自己的游泳时间做了精确的计时(本题中的计时都按小时制计算),它发现自己从时分一直游泳到当天的时分,请你帮小鱼计算一下,它这天一共......
  • 202306112142-《最近开发心得...》
     没有心得就是在瞎搞,写心得就是“埋头耕耕,抬头看看”,看看自己做了什么......    心得就是心的感受,并非得到了什么,我以前是搞前端开发,仅仅4-5年时间,见证Angular市场份额的减少,backbone还嫌有耳闻,鲜有招聘;React框架从耳闻到霸屏;个人沐浴jquery的春风,枯于市场类似Vue......
  • 第四天打卡|24. 两两交换链表中的节点 ● 19.删除链表的倒数第N个节点 面试题 02.07.
    24.两两交换链表中的节点:简单的交换 19.删除链表的倒数第N个节点: ●  面试题 02.07. 链表相交:这题没看过答案真的写不出来。太巧妙了  142.环形链表II:这题写过但是忘记怎么解的了还是看的答案。下次不能忘记  ......
  • CF121E Lucky Array
    思路正解是线段树?然而我太菜了不会啊。。。题目的数据范围是\(10^5\),于是我们可以从分块的角度去思考这个问题。打个表可以发现在题目给定的值域(\(10^4\))内满足条件的数一共只有三十个,于是这道题就简单了。先把数列分个块,然后对于每一块,维护一个区间加的标记和一个值域的......
  • sb+activiti7实例<二>20230424
    一、版本问题原Activiti的TijsRademakers团队去开发Flowable框架。现Activiti7是Salaboy团队开发的,内核使用的还是Activiti6,扩展了云化。Activiti5、Activiti6代码目前由Salaboy团队代为维护,目前官宣已经暂停维护  Activiti:Activiti在目前来看有点不思进取,核心功能和内核的优......
  • 代码随想录算法训练营第四天|24. 两两交换链表中的节点 , 19.删除链表的倒数第N个节点
    24.两两交换链表中的节点 个人感觉这个不太难,刚开始打算用步进值为2,来搞,但是没有想到链表应该是怎么样的,原来可以直接用: 1cur=cur->next->next 学到了,这是我自己写的代码:1ListNode*MyLinkedList::swapPairs(ListNode*head)2{3ListNode*dummyHead=new......
  • Python小屋刷题软件2425道题目分类速查表
    “Python小屋”编程比赛正式开始Python小屋刷题软件客户端使用说明(视频讲解)Python小屋刷题神器最近升级的新功能介绍每次录入新题目时都会更新下面的分类表,请注意查看最新信息。客观题分类:Python基础知识:1-57内置函数、运算符:58-320列表、元组、字典、集合、切片、推导式:321-792选......
  • P1423 小玉在游泳
    题目描述小玉开心的在游泳,可是她很快难过的发现,自己的力气不够,游泳好累哦。已知小玉第一步能游米,可是随着越来越累,力气越来越小,她接下来的每一步都只能游出上一步距离的。现在小玉想知道,如果要游到距离米的地方,她需要游多少步呢。请你编程解决这个问题。输入格式输入一个实数......
  • 【若归】 【LGR-142-Div.4】洛谷入门赛 #13赛后反思
    比赛链接:【LGR-142-Div.4】洛谷入门赛#13rk288,比前几次差(可能是因为rated?)A十年OI一场空,不开longlong见祖宗#include<bits/stdc++.h>usingnamespacestd;intmain(){ longlongintn; cin>>n; cout<<"8"<<12*(n-2)<<""<<6*(n-......