两题都是蚂蚁爬杆问题。。所以放在一起了。
第一个是复试题,因为不同蚂蚁撞在一起交换速度,所以分情况,一动一不动相当于接力,两个相向相当于换位。所以对于速度为0的蚂蚁来说,如果左右两边都有一只朝自己走的蚂蚁,那方向不变但初始位置变成最后交换位置的蚂蚁初始位置。
仔细想想(想的过程就不说了)就可以变成首先计算出左右两方各有多少蚂蚁,把能够遇见的蚂蚁当成同归于尽,不动蚂蚁落下的时间就是未同归于尽第一个活着的蚂蚁落下的时间,不动蚂蚁落下的方向就是左右双方数量多的一方的方向。最后模拟即可。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <climits>
using namespace std;
const int INF = INT_MAX;
int FindCommon(int x, int y){
int minabs = min(abs(x), abs(y));//找出公共部分(同归于尽部分)的绝对值
if(x+y > 0) return minabs+1;
else if(x+y < 0) return -(minabs+1);
else return 0;
}
int main(){
// freopen("in.txt", "r", stdin);
int N, pos, way, current, change, number, number1, number2;
int stick[105];
while(~scanf("%d", &am