Codechef December Challenge 2014 Chef and Apple Trees 水题
Chef and Apple Trees
Chef loves to prepare delicious dishes. This time, Chef has decided to prepare a special dish for you, and needs to gather several apples to do so.
Chef has N apple trees in his home garden. Each tree has a certain (non-zero) number of apples on it. In order to create his dish, Chef wants to pluck every apple from every tree.
Chef has an unusual method of collecting apples. In a single minute, he can perform the following task:
- Pick any subset of trees such that every tree in the subset has the same number of apples.
- From each tree in the subset, pluck any number of apples, as long as the number of apples left on the tree equals the number of apples on a tree not in the subset.
If all trees have the same number of apples left, Chef can pluck all of the apples remaining in a single minute.
Chef does not want to keep you waiting, so wants to achieve this task in the minimum possible time. Can you tell him what the minimum time required is?
Input
The first line of the input contains a single integer T denoting the number of test cases. This will be followed by T test cases. The first line of each test case contains a single integer N denoting the number of apple trees in Chef's garden. The next line of each test case contains N space separated integers denoting the number of apples on each tree.
Output
For each of the T test cases, output a single line - the minimum time to pluck all apples from all trees.
Constraints
- 1 <= T <= 10
- 1 <= N <= 105
- 1 <= Number of apples on a tree <= 105
Scoring
- Subtask 1 : 1 <= T <= 10 , 1 <= N <= 103: (27 pts)
- Subtask 2 : 1 <= T <= 10 , 1 <= N <= 104: (25 pts)
- Subtask 3 : 1 <= T <= 10 , 1 <= N <= 105: (48 pts)
Example
Input
2
3
3 3 3
4
1 2 3 3 Output
1
3
Explanation
For test 1, Chef can select all the trees and can pluck all the apples in 1 minute.
For test 2, there are many ways Chef can pluck all of the apples in 3 minutes. Here is one example:
- First minute: Select the third and fourth trees. Pluck 1 apple from the third tree, and 2 apples from the fourth tree.
- Second minute: Select the second and third tree. Pluck 1 apple from each tree.
- Third minute: Select all of the trees and pluck the last apple from each tree.
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100001
int a[maxn];
int flag[maxn];
int main()
{
int t;
cin>>t;
while(t--){
int n;
scanf("%d",&n);
int ans=;
memset(flag,,sizeof(flag));
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
if(flag[a[i]]==)
ans++;
flag[a[i]]=;
}
cout<<ans<<endl;
}
return ;
}
Codechef December Challenge 2014 Chef and Apple Trees 水题的更多相关文章
- codeforces 558A A. Lala Land and Apple Trees(水题)
题目链接: A. Lala Land and Apple Trees time limit per test 1 second memory limit per test 256 megabytes ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries
https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays
https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #incl ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake
https://www.codechef.com/DEC17/problems/GIT01 #include<cstdio> #include<algorithm> using ...
- 【分块+树状数组】codechef November Challenge 2014 .Chef and Churu
https://www.codechef.com/problems/FNCS [题意] [思路] 把n个函数分成√n块,预处理出每块中各个点(n个)被块中函数(√n个)覆盖的次数 查询时求前缀和,对于 ...
- CODECHEF Nov. Challenge 2014 Chef & Churu
@(XSY)[分塊] Hint: 題目原文是英文的, 寫得很難看, 因此翻譯為中文. Input Format First Line is the size of the array i.e. \(N ...
- CodeChef November Challenge 2014
重点回忆下我觉得比较有意义的题目吧.水题就只贴代码了. Distinct Characters Subsequence 水. 代码: #include <cstdio> #include ...
- Codechef March Challenge 2014——The Street
The Street Problem Code: STREETTA https://www.codechef.com/problems/STREETTA Submit Tweet All submis ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds
https://www.codechef.com/DEC17/problems/VK18 #include<cstdio> #include<iostream> #includ ...
随机推荐
- python 根据输入的内容输出类型
类型判断 from functools import singledispatch import numbers from collections import abc from collection ...
- 微信web开发者工具无法打开的解决方法
参考网址:https://blog.csdn.net/gz506840597/article/details/77915488 我试了上面兄弟说的方法还是无效 下面说说我的方法: 我打开文件所在位置, ...
- C# WebClient进行FTP服务上传文件和下载文件
定义WebClient使用的操作类: 操作类名称WebUpDown WebClient上传文件至Ftp服务: //// <summary> /// WebClient上传文件至Ftp服务 ...
- Java 中 日期 时间 加减
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //方法1(推荐,功能强大灵活多变) Ca ...
- select into的缺点
当使用到select * into 表A from 表 B时可以复制表的结构和数据,但是千万不要忘了给新表A添加主键和索引, 因为在使用select into 时不会复制索引和主键,因此,当我 ...
- SCTF 2014 PWN400 分析
之前没有分析PWN400,现在再开一篇文章分析一下. 这个日志是我做题的一个笔记,就是说我做一步题就记录一下是实时的.所以说可能会有错误之类的. 首先程序是经典的笔记本程序,基本上一看到这种笔记本就知 ...
- canvas 笔记整理
canvas Retina 屏幕优化 /** * HiDPI Canvas Polyfill (1.0.9) * * Author: Jonathan D. Johnson (http://jonda ...
- 【POJ】1704.Georgia and Bob
题解 感觉挺神奇的 我们把石子从后往前相邻的两个两两配对,这样他们之间的空格就相当于一堆石子 而配对后左边棋子移动,右边棋子也一定可以跟上取 转化成简单的nim游戏,最后只要看转化出的这(N - 1) ...
- SPOJ - SUBLEX 后缀自动机
SPOJ - SUBLEX 思路:求第k大字串,求出sam上每个节点开始能识别多少字串,然后从起点开始跑就好啦. #include<bits/stdc++.h> #define LL lo ...
- 【Java】 参数的传递:值传递与引用传递讨论
内容稍多,可直接看第4点的讨论结果 前言 在涉及到传递参数给方法时,容易出现一些参数传递错误的问题,这就涉及到了参数的传递问题,必须搞清楚:参数是如何传递到方法中的?一般来说,参数的传递可以分为两种: ...