第五届华中区程序设计邀请赛暨武汉大学第十四届校赛 网络预选赛

Problem 1603 - Minimum Sum
Time Limit: 2000MS  Memory Limit: 65536KB 
Total Submit: 556 Accepted: 153 Special Judge: No

Description

There are n numbers A[1] , A[2] .... A[n], you can select m numbers of it A[B[1]] , A[B[2]] ... A[B[m]]  ( 1 <= B[1] < B[2] .... B[m] <= n ) such that Sum as small as possible.

Sum is sum of abs( A[B[i]]-A[B[j]] ) when 1 <= i < j <= m.

Input

There are multiple test cases.
First line of each case contains two integers n and m.( 1 <= m <= n <= 100000 )
Next line contains n integers A[1] , A[2] .... A[n].( 0 <= A[i] <= 100000 )
It's guaranteed that the sum of n is not larger than 1000000.

Output

For each test case, output minimum Sum in a line.

Sample Input

4 2
5 1 7 10
5 3
1 8 6 3 10

Sample Output

2
8

//题意:输入n,m ,接下来输入n个数
表示要从n个数里选m个数使得它们的sun值最小。sum的定义为(加个图片好难。。。)
//思路:
知道了题意就可以想方法写了,因为是相减的绝对值的关系,所以,就没必要考虑它的位置关系了,所以直接对这n个数进行排序,
选择这n个数中的m个数的最小sum就可以了,但怎么求这个最小的sum呢?
直接暴力模拟就行了,本来以为这样会超时,但没想到竟然过了。。。可能是数据水。。

 

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define IN __int64
#define N 100010
#define M 1000000007
using namespace std;
char s[N];
int main()
{
	int t,n,m,T=1;
	int i,j,k;
	while(gets(s)!=NULL)
	{
		puts(s);
	}
	return 0;
} 


 

Problem 1604 - Play Apple
Time Limit: 1000MS  Memory Limit: 65536KB 
Total Submit: 432 Accepted: 173 Special Judge: No
Description

There are N apples. Two people take turns to either:
1. Divide the apple into two piles with different numbers.
2. The other people selects a pile of apples as the beginning of the next turn.
If someone can not meet the requirements, he is lost. Will the first one win the game if both use the best strategy?

Input
There are multiple test cases.
The first line of each case contains a integer N. ( 1 <= N <= 1000000000 )
Output
If the first person will win, output “Yes”. Otherwise, output “No”.
Sample Input
2
3
4
Sample Output

No
Yes
No

//题意:

给你一堆苹果的个数,两个人依次将苹果分为个数不同的两堆,如果不能再分,那么就会输了这场比赛,你是第一个分,问你是否会赢得比赛?

//思路:

通过模拟可以找出有一个必输点(n-1)%3==0,找到这个规律就可以写这道题了。

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define IN __int64
#define N 100010
#define M 1000000007
using namespace std;
int main()
{
	ll n;
	while(scanf("%lld",&n)!=EOF)
	{
		if(n == 1 || n == 2)
			puts("No");
		else if(n == 3)
			puts("Yes");
		else
		{
			if((n - 1) % 3 == 0)
				puts("No");
			else 
				puts("Yes");
		}
	}
	return 0;
}


 

Problem 1606 - Funny Sheep
Time Limit: 1000MS  Memory Limit: 65536KB 
Total Submit: 612 Accepted: 169 Special Judge: No
Description

There are N+1 rows and M+1 columns fence with N*M grids on the grassland. Each grid has a sheep. In order to let the sheep together, we need to dismantle the fence. Every time you can remove a row or a column of fences. What’s the least number of times to reach the goal?

Input
There are multiple test cases.
The first line of each case contains two integers N and M. (1≤N,M≤1000)
Output
For each case, output the answer in a line.
Sample Input
1 2
2 2
Sample Output

1
2

//题意:

现在有一个n*m的矩形的网格栅栏,每个网格里有一头羊,问最少拆掉多少根的栅栏可以让所有的羊走到一起。

//思路:

因为是让所有的羊走到一起,所以通过模拟可以找出规律:拆的最少栅栏数为min(min(n,m),m+n-2);n表示将横行拆掉,只剩下一行

m表示将所有的纵列拆掉,只剩下一列,n+m-2表示将中间的栅栏拆掉。找到它们三个之间的最小值即可。

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define IN __int64
#define N 100010
#define M 1000000007
using namespace std;
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		int ans=min(n,m);
		ans=min(ans,n+m-2);
		printf("%d\n",ans);
	}
	return 0;
}


 

Problem 1609 - Han Move
Time Limit: 1000MS  Memory Limit: 65536KB 
Total Submit: 619 Accepted: 161 Special Judge: No
Description
Cyy and Fzz are Han Move lovers. One day, they gather together to run. They choose a circular track whose length is L m. Cyy’s speed is A m/s and Fzz’s speed is B m/s. They may choose the direction separately, i.e. they may start with the same direction or different direction. As they’re crazy, they’ll run infinitely. Gatevin, their friend, wonders the possibility of their distance is less than D m. The distance is defined as the distance on the track. The possibility is defined as the ratio between the sum of time satisfying the condition and the total time.
Input
The input file consists of multiple test cases ( around 1000000 ).
Each test case consists of 5 integers L, A, B, D, Dir in a line. The meanings of L, A, B, D are as described above. Dir means whether they are in the same direction. Dir = 1 means they are in the same direction, while Dir = 0 means they are in the opposite direction. ( 1 <= L, A, B, D <= 32768, 0 <= Dir <= 1 )
Output
For each test case, output the possibility rounded to 6 demical places in a line.
Sample Input
1200 200 400 300 0
1200 200 400 300 1
Sample Output
0.500000
0.500000
Hint

Please pay attention to the speed of I/O.

//题意:

输入l,a,b,d,dd,l表示操场的长度,a表示第一个人的速度,b表示第二个人的速度,d表示追踪距离的最大值(两人之间的距离<=d时即为追踪)

dd表示方向,0表示他俩反向,1表示他俩同向。

两个人出发点在操场上同一点沿着操场一直无限的跑圈,问他们之间的距离为追踪距离的时间与他们跑的总时间的比值。

//思路:

因为他俩是在无限的跑圈,速度不变,所以只用求出他俩共同跑完一圈的比值就是最终的比值了。

首先得明确一下他俩在一圈内会有两段追踪距离的时间(刚开始时和第二次即将相遇时),不理解的可以画个圈模拟一下就明白了。

其次求比值就得分情况了:

1、他俩同向:他们的共同速度为sum=fabs(a-b),所以他们跑一圈的总时间为tt=l/sum;他们在追踪的时间为t=d/sum*2(2为他们在一圈内会有两次相遇)。

2、他俩反向:他们的共同速度为sum=a+b,所以他们跑一圈的总时间为tt=l/sum;他们在追踪的时间为t=d/sum*2(2为他们在一圈内会有两次相遇)。

然后他们的比值即为ans=t/tt;

当然这只是两个大的方面,还有一些特殊情况得特殊判断,所以得加一些特判。(具体看代码)

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define IN __int64
#define N 100010
#define M 1000000007
using namespace std;
int main()
{
	double l,a,b,d;
	int dd;
	while(scanf("%lf%lf%lf%lf%d",&l,&a,&b,&d,&dd)!=EOF)
	{
		int sum;
		double ans,t,tt;
		if(d>=l)
		{
			printf("1.000000\n");
			continue;
		}
		if(a==b&&dd==1&&d==0)
		{
			printf("1.000000\n");
			continue;
		}
		if(d==0)
		{
			printf("0.000000\n");
			continue;
		}
		if(dd==0)
		{
			sum=a+b;
			tt=l*1.0/sum;
			t=2*d*1.0/sum;
			ans=t/tt;
		}
		else
		{
			sum=fabs(a-b);
			if(sum==0)
			{
				printf("1.000000\n");
				continue;
			}
			tt=l*1.0/sum;
			t=2*d*1.0/sum;
			ans=t/tt;
		}
		if(ans>=1)
			printf("1.000000\n");
		else
			printf("%.6lf\n",ans);
	}
	return 0;
} 


 

Problem 1611 - Null
Time Limit: 1000MS  Memory Limit: 65536KB 
Total Submit: 266 Accepted: 220 Special Judge: No
Description

  Null.

Input
Null
Output
Output “Null” in a line.
Sample Input
Null
Sample Output

Null

//题意:

输入一个字符串,将这个字符串原样输出。

Hait:别被题目迷惑,只输出Null,第一次这样写了,果断WA。

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define IN __int64
#define N 100010
#define M 1000000007
using namespace std;
char s[N];
int main()
{
	int t,n,m,T=1;
	int i,j,k;
	while(gets(s)!=NULL)
	{
		puts(s);
	}
	return 0;
} 


 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值