博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 2756 & UVA 11572 Unique Snowflakes
阅读量:5154 次
发布时间:2019-06-13

本文共 2393 字,大约阅读时间需要 7 分钟。

Problem Description
Emily the entrepreneur has a cool business idea: packaging and selling snowflakes. She has devised a machine that captures snowflakes as they fall, and serializes them into a stream of snowflakes that flow, one by one, into a package. Once the package is full, it is closed and shipped to be sold.
The marketing motto for the company is "bags of uniqueness." To live up to the motto, every snowflake in a package must be different from the others. Unfortunately, this is easier said than done, because in reality, many of the snowflakes flowing through the machine are identical. Emily would like to know the size of the largest possible package of unique snowflakes that can be created. The machine can start filling the package at any time, but once it starts, all snowflakes flowing from the machine must go into the package until the package is completed and sealed. 
 

 

Input
The first line of each test chunk contains an integer specifying the number of test cases in this chunk to follow. Each test case begins with a line containing an integer n, the number of snowflakes processed by the machine. The following n lines each contain an integer (in the range 0 to 10^9, inclusive) uniquely identifying a snowflake. Two snowflakes are identified by the same integer if and only if they are identical. The input will contain no more than one million total snowflakes. 
Please process to the end of the data file.
 

 

Output
For each test case output a line containing single integer, the maximum number of unique snowflakes that can be in a package. 
 
思路类似XDOJ1175,用dp[i]记录以i结尾的最长不重复序列,用m[a[i]]记录上一次a[i]出现的下标
PS:HDU的输入与原题略有不同
#include 
#include
#include
#include
#include
#include
#include
using namespace std;#define SIZE 200005typedef long long LL;int dp[SIZE],a[SIZE],n;map
m;int main(){ // freopen("test.in","r",stdin); ios::sync_with_stdio(false); int T; while (cin >> T ) { for (int times = 1; times <= T; times ++){ m.clear(); memset(dp,0,sizeof(dp)); cin >> n; for (int i=1;i<=n;i++){ cin >> a[i]; } dp[1] = 1; m[a[1]] = 1; for (int i=2;i<=n;i++){ if (m[a[i]] == 0){ dp[i] = dp[i-1] + 1; m[a[i]] = i; } else { dp[i] = i - m[a[i]]; m.clear(); for (int j=i,k=0;k
View Code

 

转载于:https://www.cnblogs.com/ToTOrz/p/7380761.html

你可能感兴趣的文章
Ignite 配置更新Oracle JDBC Drive
查看>>
partproble在RHEL 6下无法更新分区信息
查看>>
c网购物车流程图
查看>>
xapth(笔记)
查看>>
HTTP 错误 403.6 - Forbidden 解决方案
查看>>
一个小例子介绍Obj-C的函数命名方式
查看>>
关于Bootstrap的理解
查看>>
hdu 2089 数位dp入门
查看>>
I/O的一些简单操作
查看>>
Handbook之012:函数类别构型
查看>>
php取整函数ceil,floor,round,intval的区别
查看>>
局部富文本
查看>>
例题6-7 树的层次遍历
查看>>
2019-2-15 日记
查看>>
那些年我们跳过的 IE坑
查看>>
产生式模型和判别式模型
查看>>
2015.10.13课堂
查看>>
国内最火5款Java微服务开源项目
查看>>
[国嵌攻略][038][时钟初始化]
查看>>
C#格式化字符串
查看>>