답안 #200281

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200281 2020-02-06T03:08:28 Z wjdqhdhfflavldkem12 곡선 자르기 (KOI17_cut) C++14
0 / 100
5 ms 376 KB
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

#define LEFT 0
#define RIGHT 1
#define node pair<int, bool>

int n, inX, outX;
vector<node> LIST;

bool compare(node a, node b){
	return a.first < b.first;
}

int main(){
	int i;

	scanf("%d", &n);

	int xtemp, ytemp;
	vector<int> x, y;
	for (i = 0; i < n; i++){
		scanf("%d %d", &xtemp, &ytemp);
		x.push_back(xtemp);
		y.push_back(ytemp);
	}
	x.push_back(x[0]);
	y.push_back(y[0]);
	x.push_back(x[1]);
	y.push_back(y[1]);

	int size = 0;
	for (i = 0; i < n; i++){
		if ((y[i]>0 && y[i + 1]<0) || (y[i]<0 && y[i + 1]>0)){
			if (size != 0 && size % 2 == 1){
				LIST.push_back(node(x[i], !LIST[size-1].second));
				size++;
			}
			else if (x[i + 1]<x[i + 2]){
				size++;
				LIST.push_back(node(x[i], LEFT));
			}
			else{
				size++;
				LIST.push_back(node(x[i], RIGHT));
			}
		}
	}
	/*
	for (i = 0; i < size; i++){
		printf("%d\t%d\n", LIST[i].first, LIST[i].second);
	}
	*/
	sort(LIST.begin(), LIST.end(), compare);
	/*
	printf("\n");
	for (i = 0; i < size; i++){
		printf("%d\t%d\n", LIST[i].first, LIST[i].second);
	}
	*/
	int count = 0;
	for (i = 0; i < LIST.size(); i++){
		if (LIST[i].second == LEFT){
			count++;
			if (count == 1)
				outX++;
		}
		else{
			count--;
			if (LIST[i - 1].second == LEFT)
				inX++;
		}
	}

	printf("%d %d\n", outX, inX);


	return 0;
}

Compilation message

cut.cpp: In function 'int main()':
cut.cpp:66:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < LIST.size(); i++){
              ~~^~~~~~~~~~~~~
cut.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
cut.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &xtemp, &ytemp);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Incorrect 5 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Incorrect 5 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Incorrect 5 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -