結果

問題 No.635 自然門松列
ユーザー furafura
提出日時 2020-10-19 03:31:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 650 ms
コード長 777 bytes
コンパイル時間 2,274 ms
コンパイル使用メモリ 199,808 KB
最終ジャッジ日時 2025-01-15 11:42:20
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:11:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         rep(i,3) scanf("%d",&x[i]);
      |                  ~~~~~^~~~~~~~~~~~
main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         rep(i,3) scanf("%d",&v[i]);
      |                  ~~~~~^~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:39:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         int q; scanf("%d",&q); rep(_,q) solve();
      |                ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const double EPS=1e-8;

void solve(){
	int x[3],v[3];
	rep(i,3) scanf("%d",&x[i]);
	rep(i,3) scanf("%d",&v[i]);

	vector<double> T={0,1e9};
	rep(i,3) rep(j,3) if(i!=j) {
		if(x[i]<x[j] && v[i]>v[j]){
			// x_i+v_i*t = x_j+v_j*t <=> t = (x_j-x_i)/(v_i-v_j)
			T.emplace_back(double(x[j]-x[i])/(v[i]-v[j]));
		}
	}

	sort(T.begin(),T.end());

	rep(i,T.size()-1){
		double t=(T[i]+T[i+1])/2;
		double a[3];
		rep(j,3) a[j]=x[j]+v[j]*t;
		if(abs(a[0]-a[1])>EPS && abs(a[1]-a[2])>EPS && abs(a[0]-a[2])>EPS){
			if((a[0]>a[1] && a[1]<a[2]) || (a[0]<a[1] && a[1]>a[2])){
				puts("YES");
				return;
			}
		}
	}
	puts("NO");
}

int main(){
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}
0