练习赛6--补题

A - Vasya and Isolated Vertices

 

Mr. Zhang recently became interested in graphic theory, so he came up with the subject of this sentence.

Find the minimum and maximum possible number of orphaned nodes in the undringed and heavy-edged undringed graph of n nodes and m-bars.

Input

The input has only one line and contains two integers n and m (1< s n < s 105,0 < m < s n s (n - 1) / 2).

The input guarantees that there is at least one n-node m-bar edge, and that there is no directional graph of self-loops and heavy edges.

Output

The output has only one row and contains two integers, min and max,representing the minimum and maximum values of the number of orphaned nodes, respectively.

Sample 

4 2

Sample Out 

0 1

题目大意及解题思路: 

给你n个点,m条边,求最多与最少的孤立顶点。

最小值:每次连一条边,可以使得两个点不再是孤立点。

最大值:连的边一定要尽量重复。考虑构造局部的完全图,先构造一个点的完全图, 再到两个,再到三个,直到再加会超出。但要特判m= 1和m=0。

代码实现:

#include<stdio.h>
#define LL long long 
LL n,m,min,max;
int main(){
    scanf("%lld %lld",&n,&m);
    if(m==0){
        min=max=n;
    }
    else{
        min=n-(m*2);
        if(min<0)
		min=0;
        int i=1;
        while(m>0){
            m-=i;
            i++;
        }
        max=n-i;
    }
    printf("%lld %lld",min,max);
    return 0;
}

B - Bus 

Suppose there is an initial $$x person on the bus, the car passes through $n$ station, and each time you board the bus, $a the person (if $a-i < 0$, which means $-a_i$person), if the car can accommodate up to $m$people and the bus is not overloaded, how likely is the value of $x $?

Enter the format

Enter two integers on the first line $n, m$.

The second line enters $n$ integers $a.i$.

The output format

Output an integer that represents how many possibilities there are for the value of $x$.

The range of data

$1 'the n' 10-3, 1 'the m' on 10-9, -10'6 'a_i 'the $10-6'

Sample Input

3 5
2 1 -3

Sample Output

3

题目大意及解题思路: 

公交车上假设初始有 x 个人,汽车经过了 n个站,每次上车 ai人(如果 ai<0,表示下车 −ai 人),如果车上最多可容纳 m 人,且公交车中途不会出现超载,那么 x的值有多少可能?

找出在行驶过程中最多人的时候和最少人的时候,再分情况讨论只有上车没下车和只下车没上车的情况

代码实现:

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int n;
	long long m,a[1005],x;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int b=a[0],c=a[0];
	int d=a[0],e=a[0];
	for(int i=1;i<n;i++)
	{
		c+=a[i];
		b=max(c,b);
		e+=a[i];
		d=min(e,d);
	}
	long long s;
	
	if(d<0&&b<0){
	if(abs(d)>m) s=0;
	else s=m+1+d;}
	else if(d>0&&b>0){
	if(b>=m) s=0;
	else s=m+1-b;}
	else {
	if(b+abs(d)>=m)
	s=0;
	else
	s=m+1-b+d;}
	cout<<s<<endl;
}

 

C - Divide Points

参考大佬:

https://blog.csdn.net/qq_45228537/article/details/103770205

You are given a set of n≥2n≥2 pairwise different points with integer coordinates. Your task is to partition these points into two nonempty groups AA and BB, such that the following condition holds:

For every two points PP and QQ, write the Euclidean distance between them on the blackboard: if they belong to the same group — with a yellow pen, and if they belong to different groups — with a blue pen. Then no yellow number is equal to any blue number.

It is guaranteed that such a partition exists for any possible input. If there exist multiple partitions, you are allowed to output any of them.

Input

The first line contains one integer nn (2≤≤103)(2≤≤103 ) — the number of points.

The ii-th of the next nn lines contains two integers xixi and andiyto (−106≤xi,andi≤106−106≤xi,yto≤106) — the coordinates of the ii-th point.

It is guaranteed that all nn points are pairwise different.

Output

In the first line, output aa (1≤has≤No.11≤has≤No.1) — the number of points in a group AA.

In the second line, output aa integers — the indexes of points that you include into group AA.

If there are multiple answers, print any.

Input

3
0 0
0 1
1 0

Output

1
1 

D - Race

题目大意及解题思路:

 设一个二维数组d[i][j],i代表马的数量,j代表名次有多少组
所以有a[1][1]=1;a[2][1]=1;a[2][2]=2;
然后就递推,有a[i][j]=j*((a[i-1][j]+a[i-1][j-1]));
前面代表把后来加上的一匹马另成一组,加入到名次中,产生的新的比赛结果(j-1组中插进去,有j个空隙去插),后面的代表把马加入到已有的组里,产生的结果(有j个组可进去)

代码实现:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=1050;
const int mod=10056;
 
long long a[maxn][maxn],b[maxn];
int n;
int main()
{
    int T;
    scanf("%d",&T);
    int t=0;
    for(int i=1;i<maxn;i++){
        a[i][1]=1;
        long long sum=1;
        for(int j=2;j<=i;j++){
            a[i][j]=j*((a[i-1][j]+a[i-1][j-1])%mod);
            sum+=a[i][j];
            sum%=mod;
        }
        b[i]=sum;
    }
    while(T--)
    {
        scanf("%d",&n);
        printf("Case %d: %lld\n",++t,b[n]);
 
    }
    return 0;
}

E - Square Coins

People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (=17^2), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland.
There are four combinations of coins to pay ten credits:

ten 1-credit coins,
one 4-credit coin and six 1-credit coins,
two 4-credit coins and two 1-credit coins, and
one 9-credit coin and one 1-credit coin.

Your mission is to count the number of ways to pay a given amount using coins of Silverland.

Input

The input consists of lines each containing an integer meaning an amount to be paid, followed by a line containing a zero. You may assume that all the amounts are positive and less than 300.

Output

For each of the given amount, one line containing a single integer representing the number of combinations of coins should be output. No other characters should appear in the output.

Sample Input

2
10
30
0

Sample Output

1
4
27

题目大意及解题思路:

给你无限个面值为1,4,9,16.....289的硬币

给你一个n ,问你用这些的硬币能用多少种方案凑出n

使用母函数求解

代码实现:

#include<stdio.h>
int a[301],b[301];
int main()
{
	int n;
	//母函数模板 
	while(scanf("%d",&n),n){
		for(int i=0;i<=n;i++){//初始化 
			a[i]=0;
			b[i]=1;
		}
		for(int i=2;i<=n;i++){//硬币的种类 
			for(int j=0;j<=n;j++){
				for(int k=0;k+j<=n;k+=i*i)
				a[k+j]+=b[j];
			}
			for(int j=0;j<=n;j++){
				b[j]=a[j];
				a[j]=0;
			}
		}
		printf("%d\n",b[n]);
	}
	return 0;
} 

F - Divided into mutual quality groups

Garlic is given nn positive integers, grouping them so that any two numbers in each group are mutually quality. How many groups should you at least divide into?

Enter the format

The first line is a positive integer nn。1≤n≤101≤≤10。

The second line is nn no greater than 1000010000 The positive integer of .

The output format

A positive integer, that is, the minimum number of groups required.

Sample Input

6
14 20 33 117 143 175

Sample Output

3

题目大意及解题思路:

给定n个正整数,将它们分组,使得每组中任意两个数互质。至少要分成多少个组?

每次将数与当前已知所有组进行判断是否可以合并,如果不可以则另起一个新组

代码实现:

#include<iostream>
#include<cstdio>  
#include<cstring>

using namespace std;
long long a[11],b[11];    
int n,i,j,c = 1;  
long long gcd(long x,long y){ //递归法判断互质  
    if(y==0) 
	return x; 
    else return gcd(y,x%y); 
}  
int main(){  
    scanf("%d",&n);  
    memset(b,1,sizeof(b)); //以便于"b[j]*=a[i];" 
    for(int i = 1;i <= n;i++){
    	scanf("%lld",&a[i]);
	}   
    b[1] = a[1];  
    for(i = 2;i <= n;i++){  
        for(j = 1;j <= c;j++){
            if(gcd(a[i],b[j]) == 1){//两个整数的最大公约数为1,即两个正整数互质 
                b[j] *= a[i];  
                break;  
            }
		}
        if(j - 1 == c) //如果上面的"break"一次都没有执行  
            b[++c] = a[i];  
    }  
    printf("%d",c); 
	return 0; 
}

  

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值