답안 #29678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
29678 2017-07-20T10:23:40 Z cdemirer The Forest of Fangorn (CEOI14_fangorn) C++14
90 / 100
2606 ms 2304 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> llp;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

int W, H;
int xg, yg;
int C, N;
vii camps;
vii trees;
vii xsort_tree;
vi ans;

bool deq(double a, double b) {
	double d = a>b?a-b:b-a;
	return d < 1e-9;
}

bool cmp(const pair<double, int> &a, const pair<double, int> &b) {
	if (deq(a.first, b.first)) return a.second < b.second;
	else return a.first < b.first;
}

vi getSeq(int a, int b) {
	vi ret;
	vector<pair<double, int> > rDif, lDif;
	vii::iterator it = lower_bound(xsort_tree.begin(), xsort_tree.end(), mp(a, -1));
	if (it != xsort_tree.end()) {
		// fill right part
		while (it != xsort_tree.end() && (*it).first == a) {
			if ((*it).second > b) rDif.pb(mp(1e20, (*it).second));
			else rDif.pb(mp(-1e20, (*it).second));
			it++;
		}
		for (; it != xsort_tree.end(); it++) {
			double tx = trees[ (*it).second ].first;
			double ty = trees[ (*it).second ].second;
			double egim = (ty - b) / (tx - a);
			rDif.pb(mp(egim, (*it).second));
		}
		sort(rDif.begin(), rDif.end(), cmp);
		for (int i = 0; i < rDif.size(); i++) {
			ret.pb(rDif[i].second);
		}
	}
	it = lower_bound(xsort_tree.begin(), xsort_tree.end(), mp(a, -1));
	if (it != xsort_tree.begin()) {
		// fill left part
		it--;
		while (it != xsort_tree.begin()) {
			double tx = trees[ (*it).second ].first;
			double ty = trees[ (*it).second ].second;
			double egim = (ty - b) / (tx - a);
			lDif.pb(mp(egim, (*it).second));
			it--;
		}
		double tx = trees[ (*it).second ].first;
		double ty = trees[ (*it).second ].second;
		double egim = (ty - b) / (tx - a);
		lDif.pb(mp(egim, (*it).second));
		sort(lDif.begin(), lDif.end(), cmp);
		for (int i = 0; i < lDif.size(); i++) {
			ret.pb(lDif[i].second);
		}
	}
	return ret;
}

inline int next(int x) {
	return (x+1)%N;
}

bool cyclequal(const vi &a, const vi &b) {
	int x = a[0];
	int p2 = 0;
	while (b[p2] != x) p2 = next(p2);
	int cnt = N;
	int p1 = 0;
	while (cnt--) {
		if (a[p1] != b[p2]) return false;
		p1 = next(p1);
		p2 = next(p2);
	}
	return true;
}

int main(int argc, char **argv) {

	//freopen("input", "r", stdin);
	//freopen("output", "w", stdout);

	scanf("%d%d", &W, &H);
	scanf("%d%d", &xg, &yg);
	scanf("%d", &C);
	camps.resize(C);
	for (int i = 0; i < C; i++) {
		scanf("%d%d", &(camps[i].first), &(camps[i].second));
	}
	scanf("%d", &N);
	trees.resize(N);
	for (int i = 0; i < N; i++) {
		scanf("%d%d", &(trees[i].first), &(trees[i].second));
		xsort_tree.pb(mp(trees[i].first, i));
	}
	sort(xsort_tree.begin(), xsort_tree.end());
	vi oseq = getSeq(xg, yg);
	for (int i = 0; i < C; i++) {
		vi s = getSeq(camps[i].first, camps[i].second);
		if (cyclequal(oseq, s)) {
			ans.pb(i+1);
		}
	}
	printf("%d\n", (int)ans.size());
	for (int i = 0; i < ans.size(); i++) {
		printf("%d ", ans[i]);
	}
	if (ans.size()>0) puts("");

	return 0;
}

Compilation message

fangorn.cpp: In function 'vi getSeq(int, int)':
fangorn.cpp:49:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < rDif.size(); i++) {
                     ^
fangorn.cpp:69:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < lDif.size(); i++) {
                     ^
fangorn.cpp: In function 'int main(int, char**)':
fangorn.cpp:121:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ans.size(); i++) {
                    ^
fangorn.cpp:99:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &W, &H);
                       ^
fangorn.cpp:100:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &xg, &yg);
                         ^
fangorn.cpp:101:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &C);
                 ^
fangorn.cpp:104:55: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &(camps[i].first), &(camps[i].second));
                                                       ^
fangorn.cpp:106:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
fangorn.cpp:109:55: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &(trees[i].first), &(trees[i].second));
                                                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Output is correct
2 Correct 0 ms 2028 KB Output is correct
3 Correct 0 ms 2028 KB Output is correct
4 Correct 0 ms 2028 KB Output is correct
5 Correct 0 ms 2028 KB Output is correct
6 Correct 0 ms 2028 KB Output is correct
7 Correct 0 ms 2028 KB Output is correct
8 Correct 0 ms 2028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Output is correct
2 Correct 0 ms 2028 KB Output is correct
3 Correct 0 ms 2028 KB Output is correct
4 Correct 0 ms 2028 KB Output is correct
5 Correct 0 ms 2028 KB Output is correct
6 Correct 0 ms 2028 KB Output is correct
7 Incorrect 0 ms 2028 KB Output isn't correct
8 Correct 0 ms 2028 KB Output is correct
9 Correct 0 ms 2028 KB Output is correct
10 Correct 0 ms 2028 KB Output is correct
11 Correct 0 ms 2028 KB Output is correct
12 Correct 0 ms 2028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Output is correct
2 Correct 0 ms 2028 KB Output is correct
3 Correct 0 ms 2028 KB Output is correct
4 Correct 0 ms 2028 KB Output is correct
5 Correct 0 ms 2028 KB Output is correct
6 Correct 3 ms 2168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 226 ms 2160 KB Output is correct
2 Correct 2343 ms 2304 KB Output is correct
3 Correct 2606 ms 2176 KB Output is correct
4 Correct 2396 ms 2184 KB Output is correct