SDNU_ACM_ICPC_2020_Winter_Practice_4th(补题2020.2.2)

#山师寒假训练赛第四场(补题)
##H-Triangle
Mr. Frog has n sticks, whose lengths are 1,2, 3⋯n respectively. Wallice is a bad man, so he does not want Mr. Frog to form a triangle with three of the sticks here. He decides to steal some sticks! Output the minimal number of sticks he should steal so that Mr. Frog cannot form a triangle with
any three of the remaining sticks.
Input
The first line contains only one integer T (T≤20), which indicates the number of test cases.

For each test case, there is only one line describing the given integer n (1≤n≤20).
Output
For each test case, output one line “Case #x: y”, where x is the case number (starting from 1), y is the minimal number of sticks Wallice should steal.
Sample Input
3
4
5
6
Sample Output
Case #1: 1
Case #2: 1
Case #3: 2
思路:这道题能做出来,归功于以前看到过的一个知识点:斐波那契数列任意的三个数是不能组成三角形的。由此,我们便可以知道,给出的数是从1到n的,我们只要把不属于斐波那契数列的中的数找出来,就可以得到答案。
代码如下:

#include<bits/stdc++.h>
using namespace std;

int a[100];

void feibo(){
	a[0]=1;
	a[1]=1;
	for(int i=2;i<=30;i++){
		a[i]=a[i-1]+a[i-2];
	}
}

int main(){
	int m;
	int t;
	int b;
	int count=0;
	feibo();
	while(~scanf("%d",&m)){
	b=m;
	while(m--){
	scanf("%d",&t);
	for(int i=1;i<=t;i++){
		for(int k=1;k<=25;k++)
		if(i==a[k]){
		count++;
	    break;
		}
	}
	printf("Case #%d",b-m);
	printf(": %d\n",t-count);
	count=0;
    }
    }
	return 0;
}

至此开始补题
##I-Birthday Paradox
Sometimes some mathematical results are hard to believe. One of the common problems is the birthday paradox. Suppose you are in a party where there are 23 people including you. What is the probability that at least two people in the party have same birthday? Surprisingly the result is more than 0.5. Now here you have to do the opposite. You have given the number of days in a year. Remember that you can be in a different planet, for example, in Mars, a year is 669 days long. You have to find the minimum number of people you have to invite in a party such that the probability of at least two people in the party have same birthday is at least 0.5.

Input
Input starts with an integer T (≤ 20000), denoting the number of test cases.

Each case contains an integer n (1 ≤ n ≤ 105) in a single line, denoting the number of days in a year in the planet.

Output
For each case, print the case number and the desired result.

Sample Input
2

365

669

Sample Output
Case 1: 22

Case 2: 30
思路:这道题是生日悖论,具体请看我写的,只看内容,忽略字体。这个是参考网上别人的想法 原版
在这里插入图片描述
然后知道原理,就可以写代码了。还有,一定要注意输出格式,要不都不知道怎么si的

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int i;
	ll n;
	ll m;
	ll t;
	double p=1.0;
	while(~scanf("%lld",&n))
	{
		t=n;
		while(n--)
		{
			scanf("%lld",&m);
			for(i=1;;i++)
			{
				p=p*(m-i+1)/m;
				if(p<=0.5)
				break;
			}
			printf("Case %lld",t-n);
	        printf(": %d\n",i-1);
			p=1.0;
		}
	}
	return 0;
}

##L - Game with Telephone Numbers
A telephone number is a sequence of exactly 11 digits such that its first digit is 8.

Vasya and Petya are playing a game. Initially they have a string s of length n (n is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a character and erase it from the current string. For example, if the current string 1121, after the player’s move it may be 112, 111 or 121. The game ends when the length of string s becomes 11. If the resulting string is a telephone number, Vasya wins, otherwise Petya wins.

You have to determine if Vasya has a winning strategy (that is, if Vasya can win the game no matter which characters Petya chooses during his moves).

Input
The first line contains one integer n (13≤n<105, n is odd) — the length of string s.

The second line contains the string s (|s|=n) consisting only of decimal digits.

Output
If Vasya has a strategy that guarantees him victory, print YES.

Otherwise print NO.

Examples
Input
13
8380011223344
Output
YES
Input
15
807345619350641
Output
NO
Note
In the first example Vasya needs to erase the second character. Then Petya cannot erase a character from the remaining string 880011223344 so that it does not become a telephone number.

In the second example after Vasya’s turn Petya can erase one character character 8. The resulting string can’t be a telephone number, because there is no digit 8 at all.
思路:这个题,可以这样分析一下:两人各走一步,其中一人任务是消去8(后走),另一人是删去除8外的那个(先走),使最后剩下的11位是以8开头的号码,由此我们可以这样想,先不考虑后面的10,考虑前面的那些,统计前面的那些中8的个数,以及不是8的个数,如果8的个数大于等于非8的个数,那么则能够组成号码,输出YES,否则,输出NO。举个例子,假如剩下两个8,一个2,则先删2,再删一个8,剩下恰为11位以8开头的号码,加入剩下两个8,两个2,先删一个2,再删个8,再删个2,则剩下恰为11位以8开头的号码。
说的有点啰嗦了,具体看代码吧。

#include<bits/stdc++.h>
using namespace std;

char str[1000001];

int main(){
	int n;
	int m;
	int a;
	int b;
	while(cin>>n){
	scanf("%s",str);
	a=0;
	b=0;
	for(int i=0;i<n-10;i++)
	{
		if(str[i]=='8')
		a++;
		else
		b++;
	}
    if(a>=b)
    printf("YES\n");
    else
    printf("NO\n");
    memset (str,0,sizeof(str));
    }
    return 0;   
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值