1. 程式人生 > >HDU 5672:String【模擬】

HDU 5672:String【模擬】

String

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 892    Accepted Submission(s): 289


Problem Description There is a string S.S only contain lower case English character.(10length(S)1,000,000)
How many substrings there are that contain at least k(1k
26)
 distinct characters?
Input There are multiple test cases. The first line of input contains an integer T(1T10) indicating the number of test cases. For each test case:

The first line contains string S.
The second line contains a integer k(1k26).
Output For each test case, output the number of substrings that contain at least k
 dictinct characters.
Sample Input 2 abcabcabca 4 abcabcabcabc 3
Sample Output 0 55醉了,G++超時,C++過了。。。。AC-code:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int T,k,len,i,j,kk,vis[27];
	long long sum;
	char str[1000005];
	scanf("%d",&T);
	while(T--)
	{
		cin>>str;
		cin>>k;
		len=strlen(str);
		if(k==1)
		{
			cout<<(long long)(len+1)*len/2<<endl;
			continue;
		}
		kk=0;
		sum=0;
		memset(vis,0,sizeof(vis));
		j=0;
		for(i=0;i<len;i++)
		{
			if(!vis[str[i]-'a'])
				kk++;
			vis[str[i]-'a']++;
			while(kk>=k)
			{
				sum+=len-i;
				vis[str[j]-'a']--;
				if(!vis[str[j]-'a'])
				{
					kk--;
					j++;
					break;
				}
				j++;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
 } 


相關推薦

HDU 5672String模擬

String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 892    Accepted Submissi

HDU 4452 Running Rabbits 模擬

有幾個需要注意的地方:1,不用考慮在一秒內,兩個兔子移動會不會相遇,如果考慮就真的難了; 2,相遇的時候,如果到了左轉的時間,會優先處理相遇的情況;3,碰到牆反轉方向的時候,不計時; 小技巧:用編號表示方向,編號+2取餘就是反轉的方向編號,+3取餘就是左轉的方向編號,+

HDU 5983 Pocket Cube 模擬

題意:2*2*2的魔方只轉一次,問是否能讓魔方六面都相等 思路: 用陣列記錄每個面的數字,並且從1到24編號,注意這裡要根據題目要求的輸入順序編號,能一次就完成任務的情況只有兩種,一種是六面都已經滿足條件了,第二種是存在兩個對立面相等的情況,只限兩個,多一個都不行;對

HDU 1013.Digital Roots模擬或數論8月16

process clu auto white art cst int posit val Digital Roots Problem Description The digital root of a positive integer is found by su

hdu 3336 Count the stringkmp

color efi 每一個 next oid std 字符串 hdu 自身 http://acm.hdu.edu.cn/showproblem.php?pid=3336 題意:給你一個字符串,問字符串每一個前綴在字符串中的出現總次數。 思路:kmp的應用,自身和自身進行

HDU 17新生賽 身份證驗證模擬

scan n) code () int spl 自己 bug itl 身份證驗證 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis

hdu 2988 Strange fuction模擬退火

計算:給出y ,    的最小值  wa到哭啊,簡直上火了,是板子沒有套對, nex=now+T*i;//新解 T*i是變化的範圍加上原先的才是新解, 還有精確度,因為評估函式要平方,所以要高一些 最終15ms &nbs

HDU.5831 Rikka with Parenthesis II模擬8月13

As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Correct par

HDU.1896 Stones優先佇列模擬8月13

Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning and walk back every evening. Walking may cause a little tired,

HDU 2093 考試排名 排序模擬

考試排名Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14928    Accepted Submission(s

HDU 5912 Fraction 模擬 (2016中國大學生程式設計競賽(長春))

Fraction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2    Accepted Subm

HDU 5935 Car 模擬 (2016年中國大學生程式設計競賽(杭州))

Car Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 25    Accepted Submissio

Bit String Reordering UVALive - 6832 模擬

題意分析 題目講的主要是給你一個01串,然後給你要變成的01串格式,問你要轉換成這一格式最少需要移動的步數。 題目不難,但當時並沒有AC,3個小時的個人賽1道沒AC,歸根到底是沒有逼自己去想,又想的太多,還沒敢去想,還是太菜,最後把自己整崩潰了,過後看完別人程式碼發現此題並不難,模擬即可,現附具體分析如下。

模擬Flo's Restaurant

hour ++ long -s wid accep with lease ins [poj2424]Flo‘s Restaurant Time Limit: 1000MS Memory Limit: 65536K Total Submis

1069. The Black Hole of Numbers (20)模擬——PAT (Advanced Level) Practise

int exce 個人 esp ack ble sam namespace constant 題目信息 1069. The Black Hole of Numbers (20) 時間限制100 ms 內存限制65536 kB 代碼長度限制1600

poj2632 模擬

single tac 操作 vector num numbers final http format In a modernized warehouse, robots are used to fetch the goods. Careful planning is nee

NYOJ 2356: 哈希計劃模擬

++ 需要 學會 ont lld asa color 滿足 上一個 題目描述 眾所周知,LLM的算法之所以菜,就是因為成天打遊戲,最近LLM突然想玩《金庸群俠傳X》,結果進去後各種被虐,LLM就開始研究這個遊戲的代碼,順便還學會了一點點點點lua語言,然後就開始了偉大

HDU 1711 Number Sequencekmp

show turn case put next() void 出現 回首 img Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1

2016中國大學生程序設計競賽(ccpc 長春) Fraction模擬

skin 設計 中國大學 image tail action pre review 如圖所示 Problem Description Mr. Frog recently studied how to add two fractions up, and he came up

345. Reverse Vowels of a Stringeasy

not blog ive 參考 char wap ast otc emp 345. Reverse Vowels of a String【easy】 Write a function that takes a string as input and reverse o