2020寒假训练第一周 思维+模拟

这周相对来说比较简单都是基础题

同样
枯木逢春不在茂
年少且惜镜边人
直接看题吧!!!!奥利干!
1.
对于给定的一个字符串,统计其中数字字符出现的次数。

    Input
    输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一个由字母和数字组成的字符串。

    Output
    对于每个测试实例,输出该串中数值的个数,每个输出占一行。

    Sample Input
    2

asdfasdf123123asdfasdf
asdf111111111asdfasdfasdf

    Sample Output
    6
    9
#include<stdio.h>
int b[1000];
int main()
{
	int n,i,j;
	char a[2000][1000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%s",a[i]);
	for(i=0;i<n;i++)
	 for(j=0;;j++)
	{
		if(a[i][j]=='\0')
		break;
		else
		{
			if('0'<=a[i][j]&&a[i][j]<='9')
			b[i]++;
		}
	}
	for(i=0;i<n;i++)
	printf("%d\n",b[i]);		
	return 0;
}

本题就是没什么难的,知道 A[I][J]==’\0’就好了。
而且二维数组,用一位数组接受字符串,再用二维数组逐个击破每个字符,真香!
2.
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop and a d2 meter long road between his house and the second shop. Also, there is a road of length d3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house.

Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn’t mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.

    Input
    The first line of the input contains three integers d1, d2, d3 (1 ≤ d1, d2, d3 ≤ 108) — the lengths of the paths. 

d1 is the length of the path connecting Patrick’s house and the first shop;
d2 is the length of the path connecting Patrick’s house and the second shop;
d3 is the length of the path connecting both shops.

    Output
    Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.

    Examples

Input

10 20 30

Output

60

Input

1 1 5

Output

4

    Note
    The first sample is shown on the picture in the problem statement. One of the optimal routes is: house  first shop  second shop  house.

In the second sample one of the optimal routes is: house first shop house second shop house.

#include<stdio.h>
int f(int a,int b)
{
	return a>b?b:a;
}
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	printf("%d",f(a,b+c)+f(b,a+c)+f(c,a+b));
	return 0;
}

这题其实不是挺难的,但是值得一看,起初我还做错了,头疼,不知道为什么,最后发现,在你选择一条路的时候,有可能另外两条路更短,自我感觉这可能是一种小贪心吧!看代码 会懂的,毕竟我这么垃圾,都会,阁下应该超懂的吧!
3.
快到区域赛了QAQ 超级强大的学长要带着学弟和学妹去比赛,学长出马一个顶俩,但是这次却出大问题…

他们遇见很多难题…但是只要他们中的两个有思路这道题就能解出来Input第一个输入行包含一个整数n(1≤n≤1000)表示比赛中问题的数量。然后n行包含三个整数,每个整数是0或1.如果行中的数字等于1,那么学长确定问题的解决方案,否则不确定。第二个数字显示了学弟对解决方案的看法,第三个数字显示了学妹的观点。行上的数字用空格分隔。Output输出一个整数表示比赛中能够解决的问题的数量。Examples

Input

3
1 1 0
1 1 1
1 0 0

Output

2

Input

2
1 0 0
0 1 1

Output

1
题意就是学长想出来相当于2个学弟,只要再有一个就可以,当然两个学弟也可以解决出来!

#include<stdio.h>
int ans;
int main()
{
	int n,i,j;
	int a[1000][3]; 
	scanf("%d",&n);
	for(i=0;i<n;i++)
	  for(j=0;j<3;j++)
	  {
	  	scanf("%d",&a[i][j]);
	  }
	for(i=0;i<n;i++)
	  {
	  	if(a[i][0]==1&&(a[i][1]+a[i][2]!=0))
	  	ans++;
	  	if(a[i][0]==0&&a[i][1]==1&&a[i][2]==1)
	  	ans++;
	  }
	  printf("%d",ans);
	
	
	
	
	
	
	
	return 0;
}

看这个代码多么的简单直白,这才是高手,当然是别人的,我的长且粗糙,见不得人了!就看这个吧,挺好的,嘿嘿!二维数组其实也挺好用的!
4.
Vaibhav started participating in a programming contest. There are n problems in the contest. Vaibhav’s problem-solving skill is equal to k.
Vaibhav arranges all problems from the contest into a list. Because of his weird principles, Vaibhav only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Vaibhav solves is either the leftmost or the rightmost problem in the list.
Vaibhav cannot solve a problem with difficulty greater than k. When Vaibhav solves the problem, it disappears from the list, so the length of the list decreases by 1. Vaibhav stops when he is unable to solve any problem from any end of the list.
How many problems can Vaibhav solve?InputThe first line of input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of problems in the contest and Vaibhav’s problem-solving skill.
The second line of input contains n integers a1, a2, . . ., an (1 ≤ ai≤ 100), where ai is the difficulty of the i-th problem. The problems are given in order from the leftmost to the rightmost in the list.OutputPrint one integer — the maximum number of problems Vaibhav can solve.Examples

Input

8 4
4 2 3 1 5 1 6 4

Output

5

Input

5 2
3 1 2 1 3

Output

0

Input

5 100
12 34 55 43 21

Output

5

NoteIn the first example, Vaibhav can solve problems in the following order: [4, 2, 3, 1, 5, 1, 6, 4] → [2, 3, 1, 5, 1, 6, 4] → [2, 3, 1, 5, 1, 6] → [3, 1, 5, 1, 6] → [1, 5, 1, 6] → [5, 1, 6], so the number of solved problems will be equal to 5.
In the second example, Vaibhav can’t solve any problem because the difficulties of problems from both ends are greater than k.
In the third example, Vaibhav’s solving skill is so amazing that he can solve all the problems.
解释:此题从数列前后统计不大于k的数字个数即可。

#include<stdio.h>
int ans,t;
int main()
{
	int a[1000];
   int n,l,i,j,k,flag=0;
   scanf("%d %d",&n,&k);
   for(i=0;i<n;i++)	
	scanf("%d",&a[i]);
    i=0;
    j=n-1;
	while(i < j)        
	{
		if(a[i]<=k)            
		{
		i++;
		t++;
		flag=1;
	    }
		if(a[j]<=k)
		{
		j--;
		t++;
		flag=1;
	    }
	    if(flag==0)
	    {
	    	printf("%d",t);
	    	break;
		}
		flag=0;
	}
	if(i==j&&a[i]<=k)
	printf("%d",t+1);
	else if(i==j&&a[i]>k)
	printf("%d",t);
	else if(i>j)
	printf("%d",t);
	return 0;
}

这一看就是鄙人写的代码,比较垃圾,就是模拟这个过程而已,哎,我是垃圾,我是垃圾!
我也不知道第几题了,就空行吧!

作为集训队的dalao,lgc学长在2021年暑假成功的找到了一份满意的实习工作,大家想不想像lgc学长一样优秀呢?快刷题吧!

学长在他实习的公司附近租了一间房,学长每天坐公共汽车上下班,上下班,人来人往,学长觉得好无聊啊,于是学长突然想出了一个关于乘车的问题,lgc学长的观察能力惊人!

学长坐的公共汽车共有n个站点,学长从第一站开始坐。在她之前车上没有乘客。学长想的问题是这个车最少需要多少个座位才能保证每个人都能有座位坐。Input第一行,输入一个整数n(2≤n≤1000),表示汽车停靠的次数。

接下来是n行,每行包含两个整数a和b(0≤a,b≤1000)表示在这个站点下车的乘客数量,以及上车的乘客数量。汽车从第一个站点按顺序开往最后一个站点。Output输出汽车最少需要的座位数。
Sample Input
4

0 3

2 5

4 2

4 0
Sample Output
6

#include<stdio.h>
int d[1000];
int main()
{
	int n,i,j,a[1000],b,c,t=-1;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&b,&c);
		a[i]=c-b;
	}
	d[0]=a[0];
	for(i=1;i<n;i++)
	{
		d[i]=d[i-1]+a[i];
		
	}
	for(i=0;i<n;i++)
	{
		if(d[i]>t)
		{
			t=d[i];
		}
	}
	printf("%d",t);
	return 0;
}

哎,水题,哥们也不多说了,直接看代码吧!

TANG最近想换一个新密码,然而他忙着刷题(太强了),没空去想这个新密码(orz)。现在他需要你的帮助。

TANG决定新密码应该满足以下条件:

密码的长度必须等于n,

密码只能由小写的拉丁字母组成,

密码中不同符号的数量必须等于k,

密码中的任何两个连续的符号必须是不同的。

你的任务是帮助忙碌的TANG,发明一个新的密码,满足所有给定的条件。
(虽然我觉得他大概不会真的用这个)Input第一行输入两个数n和k,2<=n<=100,2<=k<=n,且k不超过26,因此这个密码一定存在output输出任意一个满足条件的密码Example

Input

4 3

Output

java

Input

6 6

Output

python

Input

5 2

Output

phphp

Note在第一个测试中,有一个合适的新密码–java,因为它的长度等于4和3个不同的小写字母a,j和v。

在第二个测试中,有一个合适的新密码 - python,因为它的长度等于6,它由6个不同的小写字母组成。

在第三个测试中,有一个适当的新密码 - phphp,因为它的长度等于5和2使用不同的小写字母p和h。

注意在测试中所有适当的密码都不是连续的两个相同的符号是正确的。

#include<stdio.h>
int main()
{
	int m,n,i,j,t=0,x,d=0;
	char a[1000];
	scanf("%d %d",&m,&n);
	  for(j=0;j<m;j++)
	  {
	  	a[j]='a'+t;
	  	t++;
	  	if(t==n)
	  	break;
	  }
	  for(i=n;i<m;i++)
	  {
	  a[i]=a[0+d];
	  d++;
	  if(d==n)
	  d=0;
      }
	  for(i=0;i<m;i++)
	  printf("%c",a[i]);
	  return 0;
}

既然找不一样的,那就abcd先把不一样的弄出来,然后不停复制以前的就ojbk了!!哈哈哈哈

HDU ACM集训队的队员在暑假集训时经常要讨论自己在做题中遇到的问题.每当面临自己解决不了的问题时,他们就会围坐在一张圆形的桌子旁进行交流,经过大家的讨论后一般没有解决不了的问题,这也只有HDU ACM集训队特有的圆桌会议,有一天你也可以进来体会一下哦:),在一天在讨论的时候,Eddy想出了一个极为古怪的想法,如果他们在每一分钟内,一对相邻的两个ACM队员交换一下位子,那么要多少时间才能得到与原始状态相反的座位顺序呢?(即对于每个队员,原先在他左面的队员后来在他右面,原先在他右面的队员在他左面),这当然难不倒其他的聪明的其他队友们,马上就把这个古怪的问题给解决了,你知道是怎么解决的吗?

    Input
    对于给定数目N(1<=N<=32767),表示有N个人,求要多少时间才能得到与原始状态相反的座位顺序(reverse)即对于每个人,原先在他左面的人后来在他右面,原先在他右面的人在他左面。 



    Output
    对每个数据输出一行,表示需要的时间(以分钟为单位) 



    Sample Input
    4

5
6

    Sample Output
    2

4
6

#include<stdio.h>
int f(int a)
{
	int n,n1,s,s1;
	n=a/2;
	n1=a-n;
	s=n*(n-1)/2;
	s1=n1*(n1-1)/2;
	s=s+s1;
	return s;
}
int main()
{
	int a,i;
	while(~scanf("%d",&a))
	{
		a=f(a);
		printf("%d\n",a);
	}
	  return 0;
}

这里是把圆桌分为两部分,每部分要是都换一边就得用等差数列求和公式去算,挺难的!

凯蒂、库罗和Shiro是最好的朋友。他们从幼儿园就认识了。这就是为什么他们经常互相分享一切,一起解决一些非常困难的问题。
今天是Shiro的生日。她真的很喜欢披萨,所以她想邀请她的朋友到她家附近的披萨餐厅庆祝她的生日,包括她最好的朋友凯蒂和库罗。
为了招待她的朋友们,她点了一个很大的圆形比萨饼。一共有 n 个Shiro的朋友来到这里. 这就是为什么她要把披萨分成 n + 1 份 (Shiro 也需要吃). 她希望切片的大小和形状完全相同。如果没有,她的一些朋友就会生气,提前回家,聚会就结束了。
Shiro 现在很饿. 她想用最小的直刀数去切披萨,刀线是一条直线,它可能有两端在披萨里面或外面。但是她太懒了,不想拿起计算器。
像往常一样,她会向凯蒂和库罗寻求帮助。但是他们还没有来。你能帮Shiro解决这个问题吗?Input第一行行包含一个非负整数 n (0 ≤ n ≤ 1018)— Shiro的朋友的数量。 圆形的披萨要切成 n + 1 块。Output一个整数——Shiro需要的直刀切的刀数。Examples

Input

3

Output

2

Input

4

Output

5

Note要把圆形披萨切成四分之一的大小,你必须从中间切两刀,夹角为90° 。
要把圆形披萨切成五等份,就得切五下.

#include<stdio.h>
int main()
{
	long long int n;
	scanf("%lld",&n);
	if(n==0)
	printf("0");
	else
	printf("%lld",(n+1)%2==0?(n+1)/2:n+1);
}

实在不知道怎么切,于是小看了一下,哇喔 ,这么简单!

还记得中学时候学过的杨辉三角吗?具体的定义这里不再描述,你可以参考以下的图形:

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

    Input
    输入数据包含多个测试实例,每个测试实例的输入只包含一个正整数n(1<=n<=30),表示将要输出的杨辉三角的层数。

    Output
    对应于每一个输入,请输出相应层数的杨辉三角,每一层的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。

    Sample Input
    2 3

    Sample Output
    1

1 1

1
1 1
1 2 1

#include<stdio.h>
int f(int n)
{
	int b[1000]={1};
	int i,j;
	for(i=0;i<n;i++)
	{
		for(j=i;j>0;j--)
		
			b[j]=b[j]+b[j-1];
		printf("1");
		for(j=1;j<=i;j++)
		
		printf(" %d",b[j]);
	
	    printf("\n");
	}
	printf("\n");
}
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		f(n);
	}
	  return 0;
}

哎,都会杨辉三角,注意格式就行

JK学长想对整数的数字求和来找到正整数的数字根。整数根的定义如下:如果结果值是单个数字,则该数字是数字根。如果结果值包含两个或更多个数字,则对这些数字求和并重复该过程。只要需要获得一位数,这就会继续。

例如,考虑正整数24.加上2和4得到值6.由于6是单个数字,6是24的数字根。现在考虑正整数39.加上3和9的收益率12.由于12不是一个数字,因此必须重复该过程。添加1和2 yeilds 3,单个数字以及39的数字根。

Input输入文件将包含一个正整数列表,每行一个。输入的结尾将由整数值零表示。每次输入的数据不超过10^1000。

Output对于输入中的每个整数,在输出的单独行上输出其数字根。.

Sample Input24
39
0Sample Output6
3

#include<string.h>
#include<stdio.h>
char s[1010],h[1010];
int fun(char s[1010]) {
	int sum=0;
	int a;
	int t=0;
	for(int i=0; s[i]!='\0'; i++)
	 {
		sum+=(s[i]-'0');
	}
	if(sum>=10) {
		sprintf(s,"%ld",sum);
		fun(s);
	} 
	else printf("%ld\n",sum);
}
int main() 
{
	scanf("%s",s);
	while(s[0]!='0') {
		fun(s);
		scanf("%s",s);
	}
	return 0;
}

这道题数据很大,用int就完蛋,得用字符存储,其他的好办,其次就是sprintf(s,"%ld",sum);这个函数在#include<string.h>作用就是清空s然后把sum给s,就o了

一段回文(palindrome)是指这段文字正着读和倒着读完全一致。例如:“kek”, “abacaba”, “r” 和 “papicipap"都是典型的回文,但是"abb” and "iq"这二者都不是回文。
字符串像s[l…r] (1 ≤ l ≤ r ≤ |s|)这样从s = s_1 s_2… s_|s|中选取的子字符串实际上是s_l s_(l + 1)… s_r.
Anna不喜欢回文,所以她让她的朋友们叫她Ann. 她也把她碰到的所有回文这么处理. 也就是说,每个 s 都被改成它们不是回文的最长子字符串. 如果字符串 s 的子字符串都是回文,她就跳过不读这个单词.
一次Anna读到一个单词 s . 她会怎么处理呢?Input第一行包括非空字符串s其最大长度为50字符,只包括小写字母.Output如果 s 的子字符串中包含非回文的字符串,请输出最长的结果,否则,请输出0.
特别地,我们约定,所有子字符串长度互不相等.Examples

输入:

mew

输出:

3

输入:

wuffuw

输出:

5

输入:

qqqqqqqq

输出:

0

Note"mew" 不是回文,所以其最大的非回文子字符串是 “mew” 自身. 因此,这个示例的答案是 3 .
字符串 "uffuw"是长度为 5 的 "wuffuw"的最大非回文子字符串,所以,第二个示例的答案是 5 .
字符串 “qqqqqqqq” 所有的字符都相等.这样的字符串不包括非回文字符串. 因此,示例三的答案是 0 .Hint用strcmp() strcpy() strncpy() strrev()

#include<stdio.h>
#include<string.h>
int main()
{
	int n,i,j,flag=0,t=0;
	char a[1000];
	scanf("%s",a);
	i=0;
	j=strlen(a)-1;
	n=j;
	if(j==0)
	{
		printf("0");
		return 0;
	}
	while(i<j)
	{
		if(a[i]==a[j])
		{
			flag=1;
		}
		else 
		{
			flag=0;
			break;
		}
		i++;
		j--;
	}
	if(flag==0)
	printf("%d",strlen(a));
	else 
	{
		for(i=0;i<strlen(a);i++)
		{
			if(a[i]==a[0])
			{
				t=0;
			}
			else
			{
				t=1;
				break;
			}
		}
		if(t==1)
		printf("%d",strlen(a)-1);
		else
		printf("0");
	 } 
}

看着很简单是回文就输出长度减一,或者就看是一串相同的就是0,不同的就直接输出字符串就行了

一天敏敏学姐和周老师进行一个游戏
游戏开始时在黑板上写有n个数字 a1,a2,……,an。 每一轮由一个人选择一个数字,并将它从黑板上擦去。 这个游戏直到黑板上只剩下一个数字时结束也就是说会有 n - 1 轮游戏进行。第一个玩家进行第一轮操作,第二个个玩家进行之后的一轮操作。
敏敏学姐作为先手,希望最后黑板上留下来的数字越小越好;而作为后手的周老师希望最后黑板上留下来的数字越大越好。
敏敏学姐想知道如果两个人都采取最优的策略 n - 1 轮后黑板上留下来的数字是多少。Input第一行包含一个整数n(1 ≤ n ≤ 1000)黑板上初始的数字个数。
第二行包含 n 个整数 a1,a2,……,an (1 ≤ ai ≤ 10^6)。Output输出最后会留在黑板上的数字。Examples

Input

3
2 1 3

Output

2

Input

3
2 2 2

Output

2

Note在第一个例子中,敏敏学姐会先擦去3之后周老师会擦去1。2被留在了黑板上
在第二个例子中,无论采取什么样的操作2都会留在黑板上

#include<stdio.h>
int main()
{
	int n,i,j,k=0,x,t;
	int a[10000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	for(i=0;i<n;i++)
	 for(j=i+1;j<n;j++)
	 {
	 	if(a[i]<a[j])
	 	{
	 		t=a[j];
	 		a[j]=a[i];
	 		a[i]=t;
		 }
	 }
	 x=n;
	 i=0;j=n-1;
	 while(n!=1)
	 { 
	 	if(k==0)
	 	{                           
	 		a[i]=0;                   
			i++;
			n--;
	 		k=1;
	 		continue;
		}
		if(k==1)
		{
			a[j]=0;
			j--;
			n--;
			k=0;
			continue;
		}
	 }
	 for(i=0;i<x;i++)
	 {
	 	if(a[i]!=0)
	 	printf("%d",a[i]);
	 }
}

先排序,在模拟过程!你会读吗?so easy!

好题来了!

一日,话说0068与***泛舟湖上。忽见岸边出现他的一大敌人elnil。0068当然不想落入elnil的魔爪,于是他就得想办法逃脱。

这个湖是一个很规则的圆形,半径为R。此时0068正好在圆心位置。小船在湖中的速度为 V1,0068和elnil在岸上的速度都为V2。也就是说,如果0068在刚上岸的时候没被抓到,则他可逃脱。在任意时刻,0068和elnil都可以朝任何方向移动,但是0068不能一直呆上船上(会饿死的),elnil不能下水(他不会游泳)。假设0068和elnil都非常聪明,总能做对自己最有利的事情,而且两个人的体力都是无限的。

请问,0068最终能不能逃脱elnil的魔爪?

    Input
    本题目包含多组测试。请处理到文件结束。 

每组测试包含三个整数,R,V1,V2。

    Output
    对于每组数据,如果0068能够安全逃脱,输出Yes,否则输出No。 

数据不会出现正好抓到的情况,所以你可不用太考虑临界点。

    Sample Input
    100 10 20

100 10 50

    Sample Output
    Yes

No

  #include <stdio.h>
  #define PI 3.1415926
  int main()
  {
      double r,v1,v2,t1,t2,rr;
      while(~scanf("%lf %lf %lf",&r,&v1,&v2))
      {
         rr=v1*r/v2;
		t1=(r-rr)/v1;
        t2=(PI*r)/v2;
         if(t1<t2)
             printf("Yes\n");
         else
             printf("No\n");
     }
     return 0;
 }

这是一个同心圆问题,在里面的时候 线速度大,利用这个优势可以滚雪球一直滚到第二次(第一次是开始)和奥利给角速度相同的时候也就是W=VR = VR这个时候,下来就是兽性爆发冲啊!!

一个手风琴是一个字符串(是的,在现实世界中,手风琴是一种乐器,但让我们暂时忘记它)可以表示为以下内容的串联:’[’(ASCII码091),’ : ‘(ASCII码058) ),一些(可能为零)’ | '(ASCII代码124),另一个‘ : ’和 ’ ] 'ASCII代码093)。 手风琴的长度是其中的字符数。
例如, [::], [:||:] 和 [:|||:] 是长为 $ 4 4 4$, $ 6 6 6$ and $ 7 7 7$的手风琴. (😐:), {:||:}, [:], ]:||:[ 不是手风琴
给您一个字符串s。 您想通过从中删除一些(可能为零)字符来将其转换为手风琴。 请注意,您不得插入新字符或对现有字符重新排序。 是否可以通过从s中删除字符来获得手风琴,如果可以,结果的最大可能长度是多少?Input唯一的行包含一个字符串s(1≤| s |≤500000)。 它由小写拉丁字母和字符[,] 、:和|组成。Output如果无法通过从s除去某些字符来获得手风琴,则输出-1。 否则,输出最终的手风琴的最大可能长度。Examples

Input

|[a🅱️|]

Output

4

Input

|]:[|:]

Output

-1
这个题一开始没看,最后看了一下,有点像做过的括号匹配问题,但是又不是,哎,这还是去镇上买菜的时候坐我哥车里想出来的,哎,现在都走了,时间好快,哎,岁月不饶人啊!武汉加油,干!

#include<stdio.h>
#include<string.h>
int main()
{
	char a[500010];
	int i,j,t=0;
	gets(a);
	i=0;
	j=strlen(a)-1;
	while(i<j)
	{
		if(a[i]!='[')
		i++;
		else if(a[j]!=']')
		j--;
		else
		break;
	}
	if(i==j)
	{
		printf("-1");
		return 0;
	}
	while(i<j)
	{
		if(a[i]!=':')
		i++;
		else if(a[j]!=':')
		j--;
		else
		break;
	}
	if(i==j)
	{
		printf("-1");
		return 0;
	}
	while(i!=j)
	{
		if(a[i]=='|')
		t++;
		i++;
	}
	printf("%d",t+4);
}

其实挺简单的,就是【:||||:】这么个格式哎就模拟人的思路!
There is the faculty of Computer Science in Berland. In the social net “TheContact!” for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university.
Each of students joins the group of his course and joins all groups for which the year of student’s university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don’t join other groups.
You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor’s university entrance.

    Input
    The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined. 

The next line contains n distinct integers a1, a2, …, an (2010 ≤ ai ≤ 2100) — years of student’s university entrance for each group in which Igor is the member.
It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly.

    Output
    Print the year of Igor's university entrance. 

    Examples

Input

3
2014 2016 2015

Output

2015

Input

1
2050

Output

2050

    Note
    In the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016.

In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance.

#include<stdio.h>
int main()
{
	int a[1000];
	int n,j,i,k;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	for(i=0;i<n;i++)
	 for(j=i+1;j<n;j++)
	 {
	 	if(a[j]<a[i])
	 	{
	 		k=a[j];
	 		a[j]=a[i];
	 		a[i]=k;
		 }
	 }
	 printf("%d",a[n/2]);
}

说实话这道题,我看了之后没看懂,看了别人之后发现别人,猜了一下就猜对了,就是排序后中间的那个数!哈哈哈哈哈哈,一脸闷逼
Tensor先生是当地大学系的院长。 冬季考试后,他拿到了一本小组的成绩册。

总体而言,该小组有n名学生。 他们收到了m个科目的成绩。 每个学生每个科目的成绩为1至9(含9分)。
如果一个学生在某个科目上是最好的,则我们认为这个学生是成功的。

你的任务是找到组中成功学生的数量。

Input

第一个输入行包含两个整数n和m(1≤n,m≤100) - 相应的学生数和学科数。

接下来n行包含m个字符描述成绩册。 成绩册中的每个字符都是从1到9的数字。请注意,行中的标记不是由空格分隔的。

Output

输出成功学生的数量
Example

Input

3 3
223
232
112

Output

2

Input

3 5
91728
11828
11111

Output

3

Note

在第一组样例中,科目一成绩最好的有2个人(1号和2号),科目二成绩最好的是2号,科目三中最好的成绩是2号,3号没有擅长的科目,故成功的学生有2个。

#include<stdio.h>
#include<string.h>
int c[100010];
int main()
{
	int m,n;
	int i,j,g,d=0;
	char a[100010][1000],b[100100],t='0';
	scanf("%d %d\n",&m,&n);
	for(i=0;i<m;i++)
	gets(a[i]);
	 for(i=0;i<n;i++)
	  {
	  	
	  for(j=0;j<m;j++)
	  {
	  	if(a[j][i]>t)
		  {
		  b[i]=a[j][i];
		  t=b[i];
	      }
	  }
	  t='0';
      }
    for(i=0;i<n;i++)
	 for(j=0;j<m;j++)
	 {
	 	if(b[i]==a[j][i])
	 	{
	 		c[j]++;
		}
	 }
	 for(i=0;i<m;i++)
	 {
	 	if(c[i]!=0)
	 	d++;
	 }
	 printf("%d",d);
}

用了三个数组,感觉不是很好.b[i]存的是成绩最大值,c[i]存的是哪位大佬是第一,d是有几个大佬,感觉有点复杂,哎,卑微小瑶,没办法!
Iris 在双十一买了太多的东西,所以她想从中挑出一些来送给我 。Iris 拆完了快递之后,发现自己共买了 n 个物品,第 i 个物品具有 v [ i ] 的价值 。Iris 不好意思把最便宜的给我,也舍不得把最贵的给我 。所以,对于一个物品,当且仅当存在某个其他的物品的价值严格大于这个物品,且存在某个其他物品的价值严格小于这个物品时,它才可能被送给我 。
虽然 Iris 的高数很好,但是她是个有其他事业的女人,所以她想让你帮她统计共有多少个物品可以被送给我?Input共 2 行 。
第 1 行给出 1 个整数,表示物品总数 n ( 1 <= n <= 1e5 ) 。
第 2 行给出 n 个整数,第 i 个整数表示第 i 件物品的价值 v [ i ] ( 0 <= v [ i ] <= 1e9 ) 。Output包含一个整数,表示可以被送给我的物品的件数 。ExamplesInput
2
2 6

Output
0

Input
4
2 3 3 5

#include<stdio.h>
#include<string.h>
#include<stdlib.h> 
long int s[100010];
int cmp(const void * c,const void * b)
{
return  * (int * )c- * (int * )b;
}                            
int main()
{
	long int n,g=0;
	int i;
	scanf("%ld",&n);
	for(i=0;i<n;i++)
	scanf("%d",&s[i]);
	qsort(s,n,sizeof(s[0]),cmp);
	for(i=0;i<n;i++)
	{
		if(s[i]!=s[0]&&s[i]!=s[n-1]){
		g++;
		}
	}
	printf("%d",g);
	
	return 0;
}

没什么 用快排,不然 就超时!
You are given a string ss

of length nn

, which consists only of the first kk

letters of the Latin alphabet. All letters in string ss

are uppercase.A subsequence of string ss

is a string that can be derived from ss

by deleting some of its symbols without changing the order of the remaining symbols. For example, “ADE” and “BD” are subsequences of “ABCDE”, but “DEA” is not.A subsequence of ss

called good if the number of occurences of each of the first kk

letters of the alphabet is the same.Find the length of the longest good subsequence of ss

. InputThe first line of the input contains integers nn

(1≤n≤1051≤n≤105

) and kk

(1≤k≤261≤k≤26

).The second line of the input contains the string ss

of length nn

. String ss

only contains uppercase letters from ‘A’ to the kk

-th letter of Latin alphabet.OutputPrint the only integer — the length of the longest good subsequence of string ss

.Examples Input 9 3
ACAABCCAB
Output 6 Input 9 4
ABCABCABC
Output 0NoteIn the first example, “ACBCAB” (“ACAABCCAB”) is one of the subsequences that has the same frequency of ‘A’, ‘B’ and ‘C’. Subsequence “CAB” also has the same frequency of these letters, but doesn’t have the maximum possible length.In the second example, none of the subsequences can have ‘D’, hence the answer is 00

.

#include<stdio.h>
#include<string.h>
int s[100010];
int main()
{
	char a[100010];
	int n,k,i,t=100000;
	scanf("%d %d\n",&n,&k);
	gets(a);
	for(i=0;i<n;i++)
	{
		s[a[i]-'A'+1]++;
	}
	for(i=1;i<=k;i++)
	{
		if(s[i]<t)
		t=s[i];
	}
	printf("%d\n",t*k);
	
	return 0;
}

它的要求只是求一个good子序列,即各个字母的数量相同就可以,和顺序没有关系。所以只要求出出现次数最少的字母的数量乘于k就是答案。别人的思路看起来如此如鱼得水!bang
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two “New Year and Christmas Men” meet, thear assistants cut out of cardboard the letters from the guest’s name and the host’s name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters’ names. Then he may have shuffled the letters and put them in one pile in front of the door.
The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.
Help the “New Year and Christmas Men” and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.

    Input
    The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.

    Output
    Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.

    Examples

Input

SANTACLAUS
DEDMOROZ
SANTAMOROZDEDCLAUS

Output

YES

Input

PAPAINOEL
JOULUPUKKI
JOULNAPAOILELUPUKKI

Output

NO

Input

BABBONATALE
FATHERCHRISTMAS
BABCHRISTMASBONATALLEFATHER

Output

NO

    Note
    In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.

In the second sample letter “P” is missing from the pile and there’s an extra letter “L”.
In the third sample there’s an extra letter “L”.

#include<stdio.h>
#include<string.h>
int a[100];
int main()
{
	char s[10000],b[100000],c[1000000];
	int i,j,k,t;
	scanf("%s",s);
	for(i=0;s[i];i++)
	a[s[i]-'A']++;
	
	
	
	scanf("%s",b);
	for(i=0;b[i];i++)
	a[b[i]-'A']++;
	
	
	scanf("%s",c);
	for(i=0;c[i];i++)
	a[c[i]-'A']--;
	int flag=1;
	for(i=0;i<30;i++)
	{
		if(a[i]!=0)
		flag=0;
	}
	if(flag)
	printf("YES\n");
	else
	printf("NO\n");
	return 0;
}

就是看最后一行可以拼成前两行么!看代码 理解 理解
今天就到此为止了 thank you!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值