hdoj5842【水题】
比赛的时候还特别撒比地写了二分的那个写法,然后wa了一发,因为这个集合的翻译成自然数集。还是转换了一下,还是去写了一个二分。
后面就是出现几种就是多长。。。
比赛的真的非常非常挫的code….
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define eps 1e-8
typedef __int64 LL;
const int N=1e5+10;
int d[N];
int a[N];
char s[N];
int vis[1000];
int n;
int kill(int len,int x)
{
int b=1,e=len;
while(b<=e)
{
int mid=(b+e)/2;
if(x>d[mid])
b=mid+1;
else
e=mid-1;
}
return b;
}
void Init()
{
memset(vis,0,sizeof(vis));
int cnt=1;
for(int i=1;i<=n;i++)
{
int x=s[i];
if(!vis[x])
vis[x]=cnt++;
}
}
int main()
{
int t;
int cas=1;
scanf("%d",&t);
while(t--)
{
scanf("%s",s+1);
n=strlen(s+1);
Init();
for(int i=1;i<=n;i++)
{
int x=s[i];
a[i]=vis[x];
}
d[1]=a[1];
int len=1;
int j;
for(int i=2;i<=n;i++)
{
if(d[1]>=a[i]) //如果比最小的还小
j=1;
else if(a[i]>d[len]) //如果比最大的还大
{
j=++len;
}
else
{
j=kill(len,a[i]);
}
d[j]=a[i];
}
printf("Case #%d: %d\n",cas++,len);
}
return 0;
}
hdoj5842【水题】的更多相关文章
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)
1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 154 Solved: 112[ ...
- [poj2247] Humble Numbers (DP水题)
DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...
- gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,
1195: 相信我这是水题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 821 Solved: 219 Description GDUT中有个风云人 ...
- BZOJ 1303 CQOI2009 中位数图 水题
1303: [CQOI2009]中位数图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2340 Solved: 1464[Submit][Statu ...
- 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题
B - 大还是小? Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Description 输入两个实数,判断第一个数大 ...
- ACM水题
ACM小白...非常费劲儿的学习中,我觉得目前我能做出来的都可以划分在水题的范围中...不断做,不断总结,随时更新 POJ: 1004 Financial Management 求平均值 杭电OJ: ...
- CF451C Predict Outcome of the Game 水题
Codeforces Round #258 (Div. 2) Predict Outcome of the Game C. Predict Outcome of the Game time limit ...
- CF451B Sort the Array 水题
Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...
随机推荐
- 经典游戏“大富翁4”存档文件修改器Rich4Editor下载
下载地址: http://files.cnblogs.com/files/xiandedanteng/Rich4Editor20170614.zip http://files.cnblogs.com/ ...
- 关于OC的内存管理-01
1.什么是内存管理? 大家都知道手机的内存是有限的,app应用的内存也应该是受限制的,随着app应用的使用会导致内存的占用率增大.当内存占用率达到一种程度时.系统会发出内存警告.这时我们须要把一些不用 ...
- PostgreSQL 源码解读 node的模拟实现
node的实现是PostgreSQL的查询解析的基础,实现的关键是两个宏,makeNode和newNode.其他节点继承自Node节点,如果增加新的结构体,需要添加NodeTag中添加对应的枚举值 ...
- python调用nmap进行扫描
#coding=utf-8 import nmap import optparse import threading import sys import re ''' 需安装python_nmap包, ...
- linux 标准i2c接口(一)
一:I2C设备操作方式: 1. 应用程序操作法:i2c的设备的驱动可以直接利用linux内核提供的i2c-dev.c文件提供的ioctl函数接口在应用层实现对i2c设备的读写,但是在应用层使用ioc ...
- CodeChef - PRIMEDST Prime Distance On Tree 树分治 + FFT
Prime Distance On Tree Problem description. You are given a tree. If we select 2 distinct nodes unif ...
- ElasticSearch远程随意代码运行漏洞(CVE-2014-3120)分析
原理 这个漏洞实际上非常easy,ElasticSearch有脚本运行(scripting)的功能,能够非常方便地对查询出来的数据再加工处理. ElasticSearch用的脚本引擎是MVEL,这个引 ...
- Delphi通过Get获取来自PHP的返回值
Delphi代码 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Contro ...
- react native与原生的交互
一.交互依赖的重要组件 react native 中如果想要调用ios 中相关的方法,必须依赖一个重要的组件nativemodules import { NativeModules } from ' ...
- Linux时间子系统之二:表示时间的单位和结构【转】
本文转载自:http://blog.csdn.net/droidphone/article/details/7979295 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] ...