您的位置:首页 > 其它

SDUT2015暑假集训14级周赛4

2015-08-22 21:44 302 查看
A - 那
Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d
& %I64u
SubmitStatusPracticeHDU
5056

题意:字母不超过k的子串有多少!;
思路:尺取:(O(n))

Description

You are given a string S consisting of lowercase letters, and your task is counting the number of substring that the number of each lowercase letter in the substring is no more than K.

 

Input

In the first line there is an integer T , indicates the number of test cases.

For each case, the first line contains a string which only consist of lowercase letters. The second line contains an integer K.

[Technical Specification]

1<=T<= 100

1 <= the length of S <= 100000

1 <= K <= 100000
 

Output

For each case, output a line contains the answer.
 

Sample Input

3
abc
1
abcabc
1
abcabc
2

 

Sample Output

6
15
21

#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cctype>
#include<queue>
#include<stack>
#define LL long long
#define uLL unsigned LL
#define INF 0x3f3f3f3f
using namespace std;

char s[100001];
int c[128];
int main()
{
int t,n,cnt;
while(~scanf("%d",&t))
{
while(t--)
{

scanf("%s",s+1);
scanf("%d",&cnt);
int len=strlen(s+1);
LL ans=0;
memset(c,0,sizeof(c));
int j=1;
for(int i=1;i<=len;i++)
{
ans+=j-i;
while(j<=len)
{
c[s[j]]++;
if(c[s[j]]<=cnt)
{
ans++;
j++;
}
else
break;
}
c[s[j]]--;
c[s[i]]--;

}
cout<<ans<<endl;        }
}
return 0;
}


B - 么
Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d
& %I64u
SubmitStatusPracticeHDU
2090

Description

妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐。现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵。

 

Input

输入含有一些数据组,每组数据包括菜种(字串),数量(计量单位不论,一律为double型数)和单价(double型数,表示人民币元数),因此,每组数据的菜价就是数量乘上单价啊。菜种、数量和单价之间都有空格隔开的。

 

Output

支付菜价的时候,由于最小支付单位是角,所以总是在支付的时候采用四舍五入的方法把分头去掉。最后,请输出一个精度为角的菜价总量。

 

Sample Input


青菜 1 2
罗卜 2 1.5
鸡腿 2 4.2

 

Sample Output

13.4

 

直接上代码:

#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cctype>
#include<queue>
#include<stack>
#define LL long long
#define uLL unsigned LL
#define INF 0x3f3f3f3f
using namespace std;

int main()
{
double sum;
double a,b;
char s[30]; sum=0;
while(~scanf("%s%lf%lf",s,&a,&b))
{
sum+=a*b;
}
printf("%.1lf\n",sum);
return 0;
}


C - 下
Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d
& %I64u
SubmitStatusPracticeHDU
3729

思路:二分匹配;

Description

After this year’s college-entrance exam, the teacher did a survey in his class on students’ score. There are n students in the class. The students didn’t want to tell their teacher their exact score; they only told their teacher their
rank in the province (in the form of intervals).

After asking all the students, the teacher found that some students didn’t tell the truth. For example, Student1 said he was between 5004th and 5005th, Student2 said he was between 5005th and 5006th, Student3 said he was between 5004th and 5006th, Student4
said he was between 5004th and 5006th, too. This situation is obviously impossible. So at least one told a lie. Because the teacher thinks most of his students are honest, he wants to know how many students told the truth at most.

 

Input

There is an integer in the first line, represents the number of cases (at most 100 cases). In the first line of every case, an integer n (n <= 60) represents the number of students. In the next n lines of every case, there are 2 numbers
in each line, X i and Y i (1 <= X i <= Y i <= 100000), means the i-th student’s rank is between X
i and Y i, inclusive.

 

Output

Output 2 lines for every case. Output a single number in the first line, which means the number of students who told the truth at most. In the second line, output the students who tell the truth, separated by a space. Please note
that there are no spaces at the head or tail of each line. If there are more than one way, output the list with maximum lexicographic. (In the example above, 1 2 3;1 2 4;1 3 4;2 3 4 are all OK, and 2 3 4 with maximum lexicographic)

 

Sample Input

2
4
5004 5005
5005 5006
5004 5006
5004 5006
7
4 5
2 3
1 2
2 2
4 4
2 3
3 4

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
struct node
{
int v;
int next;
}T[1000001];
int n,m;
int link[100001];
int ff[72];
bool flag[100001];
int head[72];
int top;
void build(int u,int v)
{
T[top].v=v;
T[top].next=head[u];
head[u]=top++;
}
bool DFS(int u)
{
for(int i=head[u]; i!=-1; i=T[i].next)
{
int v=T[i].v;
if(!flag[v])
{
flag[v]=1;
if(link[v]==-1||DFS(link[v]))
{
link[v]=u;
return 1;
}
}
}
return 0;
}
void hungary()
{
int k=0;
memset(link,-1,sizeof(link));
for(int i=n; i>=1; i--)
{
memset(flag,0,sizeof(flag));
if(DFS(i))
ff[k++]=i;
}
printf("%d\n",k);
sort(ff,ff+k);
for(int i=0;i<k;i++)
{
if(i!=0)
printf(" ");
printf("%d",ff[i]);
}
printf("\n");
}
int main()
{
int t;
int u,v;
while(~scanf("%d",&t))
{
while(t--)
{
top=0;
memset(head,-1,sizeof(head));
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
scanf("%d%d",&u,&v);
for(int j=u; j<=v; j++)
{
build(i,j);
}
}
hungary();
}
}
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: