问题 K: Summer Trip

题目描述
Leo has started a job in a travel agency. His first task is to organize a summer trip to an exotic overseas city. During the summer season, events of various types take place in the city: sports matches, concerts, beach parties, and many others. At any given time, there is exactly one event taking place. Events of any particular type may take place more than once during the season. The itinerary of events that Leo offers to his clients cannot be chosen arbitrarily; the company
requires them to form a so-called “good itinerary.” A good itinerary is a consecutive sequence of at least two events in the summer season, where the first and last events are of different types, and they are both unique among all event types during the sequence. For example, if the first event in a good itinerary is a beach party, none of the other events during the itinerary can also be a beach party. There are no other restrictions on the event types in the sequence of a good itinerary.
Before he starts organizing the trip, Leo wants to know the total number of good itineraries that are possible given a calendar of events that will take place over the summer season.

输入
The input consists of one line with a string describing the sequence of event types in the summer season. All characters are lowercase English letters ( ’a’ – ’z’ ), with different letters represent different types of events. Character i of the string encodes the ith event of the summer. There are no blanks or spaces in the string.
The length of the input string is at least 2 and at most 100 000 characters.

输出
Print the number of good itineraries that exist for the given summer season.

样例输入
复制样例数据
abbcccddddeeeee
样例输出
10

一个很水的题目, 但是我没想到直接暴力写, 反而想要简单的方法, 结果没找到,还没做出来, 直接枚举起点, 然后再一个枚举终点, 如果两者相同了, 那么肯定不能贡献一个答案了, 因为这个j = i + 1 , j ++ , 也就会出现起点出现在区间(i , j), 里面了, 然后j 再加加的话, 还是这个结果,有重复的出现了,所以就直接break了, 然后就是判断结尾有无出现区间里面, 可以直接做一下标记, 如果没有出现过, 那么就直接答案贡献一, 然后打上标记出现过了, 还有一个点就是用一个k来进行计数, 如果出现不同的字母26次了, 就可以结束了,因为第27次出现的,肯定会和之前的进行至少一次的重复, 就可以直接break了

#include <iostream>
#include <cstring>
#pragma GCC optimize(3 , "Ofast" , "inline")
using namespace std;
int vis[22200] ;
typedef long long ll ;
int main()
{
	string s ;
	cin >> s ;
	int len = s.size() ;
	ll ans = 0 ;
	for(int i = 0 ;i < len ; i ++)
	 {
	    int k = 1 ;
	    memset(vis , 0 , sizeof vis) ;
	    for(int j = i + 1 ;j < len && k <= 26 ;j ++)
	     {
	     	if(s[j] == s[i]) break ;
	     	if(vis[s[j]] == 0)
	     	vis[s[j]] = 1 ,	ans ++ , k ++ ;
		 }
	 }
	 printf("%lld\n" , ans) ;
	return 0 ;
} 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值