UVALive 4423 String LD 暴力
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Description
Stringld(left delete) is a function that gets a string and deletes its leftmost character (for instance Stringld(``acm") returns ``cm").
You are given a list of distinct words, and at each step, we apply stringld
on every word in the list. Write a program that determines the number
of steps that can be applied until at least one of the conditions become
true:
- A word becomes empty string, or
- a duplicate word is generated.
For example, having the list of words aab, abac, and caac, applying the function on the input for the first time results in ab, bac, and aac. For the second time, we get b, ac, and ac. Since in the second step, we have two ac
strings, the condition 2 is true, and the output of your program should
be 1. Note that we do not count the last step that has resulted in
duplicate string. More examples are found in the sample input and output
section.
Input
There are multiple test cases in the input. The first line of each test case is n(1
n
100)
, the number of words.
Each of the next n lines contains a string of at most 100 lower case characters.
The input terminates with a line containing `0'.
Output
For each test case, write a single line containing the maximum number of stringld we can call.
Sample Input
4
aaba
aaca
baabcd
dcba
3
aaa
bbbb
ccccc
0
Sample Output
1
2
#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
const int inf=0x7fffffff; //无限大 //string &erase(int pos = 0, int n = npos);//删除pos开始的n个字符,返回修改后的字符串 string s[];
int main()
{
int n;
while(cin>>n)
{
if(n==)
break;
for(int i=;i<n;i++)
cin>>s[i];
int flag=;
int flag2=;
if(n!=)
while()
{
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
if(i==j)
continue;
for(int k=;k<s[i].size();k++)
{
if(s[i][k]!='(')
break;
if(k==s[i].size()-)
{
flag2=;
break;
}
}
if(s[i]==s[j])
{
flag2=;
break;
}
}
}
if(flag2==)
break;
for(int i=;i<n;i++)
{
s[i][flag]='(';
}
flag++;
}
flag--;
if(flag<)
flag=;
cout<<flag<<endl; }
return ;
}
UVALive 4423 String LD 暴力的更多相关文章
- Gym 100299C && UVaLive 6582 Magical GCD (暴力+数论)
题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点 ...
- HDU 5944 Fxx and string(暴力/枚举)
传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Othe ...
- Nikita and string [思维-暴力] ACM
codeforces Nikita and string time limit per test 2 seconds memory limit per test 256 megabytes O ...
- HDU 4681 STRING dp+暴力。
题意:不说了很好懂. 这题这么水= =...当时竟然没有勇气暴力搜一下.昨天(好吧前天.)比赛的时候胃疼,看到这题想了一个办法就是对每一个出现最短的C串前后连接然后对这个串求最长公共子序列.其实优化一 ...
- 玲珑杯”ACM比赛 Round #4 1054 - String cut 暴力。学到了扫描的另一种思想
http://www.ifrog.cc/acm/problem/1054 问删除一个字符后的最小循环节是多少. 比赛的时候想不出,不知道怎么暴力. 赛后看了别人代码才晓得.唉,还以为自己字符串还不错, ...
- UVaLive 3401 Colored Cubes (暴力)
题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同. 析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值. 代码如下: #pragma comment(linker, &qu ...
- UVaLive 7461 Separating Pebbles (暴力)
题意:给出平面上的两类点,判断是否能画一条直线将两类点完全分割开来. 析:用暴力去枚举任意两点当作直线即可. 代码如下: #pragma comment(linker, "/STACK:10 ...
- Java基础 String 裸暴力算法- 五个小练习
之间的博客,承上启下: Java基础 String/StringBuff 常用操作方法复习/内存分析 Java数组直接选择排序.sort()排序 Java基础 String 算法 - 五个练 ...
- UVALive 4849 String Phone(2-sat、01染色)
题目一眼看去以为是4-sat... 题意:给n(n<=3000)个黑方块的坐标,保证黑方块没有公共边.对于每个黑方块选一个角作为结点,使得所选结点满足输入的一个无向图.其中距离为曼哈顿距离.输出 ...
随机推荐
- Linux USB驱动学习总结(三)---- USB鼠标的加载、初始化和通信过程
1.usbmouse的定义:usb鼠标既包含usb设备(usb_device)的属性也包含input输入设备(input_dev)的属性 struct usb_mouse { ];///USB鼠标设备 ...
- Python string interning原理
原文链接:The internals of Python string interning 由于本人能力有限,如有翻译出错的,望指明. 这篇文章是讲Python string interning是如何 ...
- 十二、springboot之web开发之静态资源处理
springboot静态资源处理 Spring Boot 默认为我们提供了静态资源处理,使用 WebMvcAutoConfiguration 中的配置各种属性. 建议大家使用Spring Boot的默 ...
- vue总结05 过渡--状态过渡
状态过渡 Vue 的过渡系统提供了非常多简单的方法设置进入.离开和列表的动效.那么对于数据元素本身的动效呢,比如: 数字和运算 颜色的显示 SVG 节点的位置 元素的大小和其他的属性 所有的原始数字都 ...
- [扩展推荐] Laravel 中利用 GeoIP 获取用户地理位置信息
我最近需要一个用户地域检测来设置用户的默认区域和货币.由 Daniel Stainback 创建的 torann/geoip 很好地满足为Laravel 5 项目提供 GeoIP 服务的要求. 这个 ...
- Centos之链接命令
链接命令:ln (link) ln -s [源文件] [目标文件] 功能描述:生成链接文件 选项: -s 创建软链接 硬链接特征: 1,拥有相同的i节点和存储block块,可以看作是同一个文件: 2 ...
- 【58沈剑架构系列】互联网公司为啥不使用mysql分区表?
缘起:有个朋友问我分区表在58的应用,我回答不出来,在我印象中,百度.58都没有听说有分区表相关的应用,业内进行一些技术交流的时候也更多的是自己分库分表,而不是使用分区表.于是去网上查了一下,并询问了 ...
- C语言:凯撒密码的实现
凯撒密码的实现(10分)题目内容: 凯撒密码(caeser)是罗马扩张时期朱利斯?凯撒(Julius Caesar)创造的,用于加密通过信使传递的作战命令.它将字母表中的字母移动一定位置而实现加密. ...
- Hadoop基准测试
其实就是从网络上copy的吧,在这里做一下记录 这个是看一下有哪些测试方式: hadoop jar /opt/cloudera/parcels/CDH-5.3.6-1.cdh5.3.6.p0.11/ ...
- 003 Ajax中传输格式为XML
一: 1.优缺点 二:大纲 1.结构设计 三:程序 1.xml <?xml version="1.0" encoding="utf-8"?> < ...