ants crash problem

  N ants are in a circular race. The length of the race is 1000 meters and ant number i is initially Vi meters far from starting point (point 0) of the race in clockwise order. All the ants walk with a speed of 0.1 meters per second, some of them walk in clockwise order, some in counter clockwise order. When two ants meet at a point, they say "Hi" to each other and both of them change their direction of walking to the opposite direction. This process is timeless, meaning they say "Hi" and change their direction in 0 seconds.

You are given the initial position of ants, you don't know their initial directions but you want to know how many times do they say "Hi" to each other after 1000000006 ( 10^9+6 seconds ). You need to find the initial walking direction of ants such that, c1+c2+c3+...+cn is maximized, where ci is the number of times ant number i say "Hi". Print this maximum value.

Input:

The first line of the input contains an integer N, the number of ants. N is not greater than 100.

Next line contains n numbers V1 , V2 , ... , VN. All Vi are non negative integers less than 1000. All Vi are distinct.

Output:

On the only line of the output print an integer being the answer to the test.

Sample Input
 
2
0 500
 
Sample Output
 
400000
 
Explanation

In the example there are two ants, In case their direction is the same, they will never say hi to each other, in the other case they will say "Hi" to each other in times 2500, 7500,12500, ... , 999999750. so the result for an Ant would be (999997500 - 2500)/5000+1 = 200000. Hence the answer is 200000*2 = 400000.

以上就是题目了:

#include <stdio.h>

int main(int argc, char * argv[])
{
	int time = 1000000006;
	int single_circle_time = 10000;
	int ants_number;
	int hit;
	int flag;
	scanf("%d", &ants_number);
	if(ants_number & 1){
		flag = 0;
	}
	else{
		flag = 1;
	}
	if(flag)
		hit = time/single_circle_time * (ants_number/2 * 2 * ants_number/2 * 2);
	else
		hit = time/single_circle_time * (ants_number/2 * 2 * (ants_number/2 + 1) * 2);
	printf("%d", hit);
	return 0;
}

代码。。。OK了。。。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值