답안 #29609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
29609 2017-07-20T08:34:57 Z cdemirer The Forest of Fangorn (CEOI14_fangorn) C++14
0 / 100
0 ms 2028 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;

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
		if ((*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());
		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());
		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:39:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < rDif.size(); i++) {
                     ^
fangorn.cpp:59: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:111:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ans.size(); i++) {
                    ^
fangorn.cpp:86:30: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("input", "r", stdin);
                              ^
fangorn.cpp:87:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("output", "w", stdout);
                                ^
fangorn.cpp:89: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:90: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:91:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &C);
                 ^
fangorn.cpp:94: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:96:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
fangorn.cpp:99: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 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
3 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
4 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
5 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
6 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
7 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
8 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
3 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
4 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
5 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
6 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
7 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
8 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
9 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
10 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
11 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
12 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 2028 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Halted 0 ms 0 KB -