8_21_2013_Problem D: BUREK_순수 시뮬레이션
Problem D: BUREK
Time Limit: 1 Sec
Memory Limit: 32 MB
Submit: 22
Solved: 14
[ Submit][ Status][ Web Board]
Description
Baker Crumble has just baked N triangular burek 2 pastries. Each pastry can be represented in the Cartesian coordinate system as a triangle with vertices in integer coordinate points. The baker's mischievous son Joey has just taken a large knife and started to cut the pastries. Each cut that Joey makes corresponds to a horizontal (y = c) or vertical (x = c) line in the coordinate system. Help the baker assess the damage caused by Joey's pastry cutting. Your task is to determine, for each Joey's cut, how many pastries are affected (such that both the left and right parts of the cut pastry have areas greater than zero).
Input
The first line of input contains the positive integer N (2 ≤ N ≤ 100 000), the number of burek pastries. Each of the following N lines contains six nonnegative integers smaller than 10 6 . These numbers are, in order, the coordinates (x1, y1), (x2, y2), (x3, y3) of the three pastry-triangle vertices. The three vertices will not all be on the same line. The pastries can touch as well as overlap. The following line contains the positive integer M (2 ≤ M ≤ 100 000), the number of cuts. Each of the following M lines contains a single cut line equation: “x = c” or “y = c” (note the spaces around the equals sign), where c is a nonnegative integer smaller than 10 6 .
Output
For each cut, output a line containing the required number of cut pastries.
Sample Input
3 1 0 0 2 2 2 1 3 3 5 4 0 5 4 4 5 4 4 4 x = 4 x = 1 y = 3 y = 1 4 2 7 6 0 0 5 7 1 7 10 11 11 5 10 2 9 6 8 1 9 10 10 4 1 4 y = 6 x = 2 x = 4 x = 9
Sample Output
0 1 1 2 3 2 3 2
HINT
In test data worth at least 40 points, M ≤ 300. In test data worth an additional 40 points, the vertex coordinates of all triangles will be smaller than 1000.
#include <iostream>
using namespace std;
struct point{
int x, y;
};
struct tri{
point p[4];
}t[100010];
int compare(int k, char line, int num){
int dis[5];
if(line=='x'){
for(int i=1; i<=3; i++){
dis[i]=t[k].p[i].x-num;
}
if( dis[1]>=0&&dis[2]>=0&&dis[3]>=0 ||
dis[1]<=0&&dis[2]<=0&&dis[3]<=0
)
{
return 0;
}
}
else{
for(int i=1; i<=3; i++){
dis[i]=t[k].p[i].y-num;
}
if( dis[1]>=0&&dis[2]>=0&&dis[3]>=0 ||
dis[1]<=0&&dis[2]<=0&&dis[3]<=0
)
return 0;
}
return 1;
}
int
main()
{
int n, m, num, sum, ans;
char line, s[10];
char ch;
while(cin>>n){
for(int i=1; i<=n; i++){
for(int j=1; j<=3; j++){
cin>>t[i].p[j].x>>t[i].p[j].y;
}
}
cin>>m;
for(int i=1; i<=m; i++){
ans=0;
cin>>line>>ch>>num;
//cout<<line<<ch<<num<<endl;
for(int i=1; i<=n; i++){
sum=compare(i, line, num);
//cout<<sum;
ans+=sum;
}
//cout<<"**";
cout<<ans<<endl;
}
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.