View Code of Problem 6

#include<iostream>
using namespace std;
struct data {
	double bg;
	double end;
	double Long;
}trap[100];
int main() {
	int t;
	cin >> t;
	while (t--) {
		int n;//陷阱数量
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			cin >> trap[i].bg >> trap[i].end;
			trap[i].Long = trap[i].end - trap[i].bg;
		}
		//初试位置
		double local = trap[0].bg;
		int j = 0;
		string isScuess = "YES";
		//弹珠跳的次数
		while(true){
			local += trap[0].Long;
			if (local >= trap[j].end && local <= trap[j + 1].bg) {
				j++;
				continue;
			}
			//最后一个陷阱
			if (j == n - 1) {
				if (local >= trap[j].end)break;
				else {
					isScuess = "NO";
					break;
				}
			}
			else break;
		}
			
		if(t!=0) cout << isScuess << endl;
		else cout << isScuess;


	}
}

Double click to view unformatted code.


Back to problem 6