码迷,mamicode.com
首页 > 其他好文 > 详细

Hidden String(判断正多边形)

时间:2015-12-06 16:03:17      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:

Hidden String

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1680    Accepted Submission(s): 592

Problem Description
Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a string s of length n. He wants to find three nonoverlapping substrings s[l1..r1], s[l2..r2], s[l3..r3] that:
1. 1l1r1<l2r2<l3r3n
2. The concatenation of s[l1..r1], s[l2..r2], s[l3..r3] is "anniversary".
 

 

Input
There are multiple test cases. The first line of input contains an integer T (1T100), indicating the number of test cases. For each test case:
There‘s a line containing a string s (1|s|100) consisting of lowercase English letters.
 

 

Output
For each test case, output "YES" (without the quotes) if Soda can find such thress substrings, otherwise output "NO" (without the quotes).
 

 

Sample Input
2 annivddfdersewwefary nniversarya
 

 

Sample Output
YES NO
 

 

Source

题意:给你一个多边形,问你这个多边形是否是正多边形。。。

题解:无奈啊,我刚开始就判断边是否相等,用差集排序,相邻判断,果断wa,又想着没考虑角度,就想着对相邻两个边求差集,是否相等,各种wa,无耐加心碎啊,然后就暴力了了。。。就判断个相等边都要大于等于2,然后就对了。。。fuck。。。

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
#define T_T while(T--)
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=210;
int N;
struct Node{
	LL x,y;
	/*Node(LL x=0,LL y=0):x(x),y(y){}*/
};
Node dt[MAXN];
/*LL cross(Node a,Node b){
	return a.x*b.y-a.y*b.x;
}

int cmp(Node a,Node b){
	if(cross(a,b)>=0)return 1;
	else return 0;
}*/
/*
Node operator - (Node a,Node b){
	return Node(a.x-b.x,a.y-b.y);
}*/
double getl(Node a,Node b){
	LL x=a.x-b.x,y=a.y-b.y;
	return sqrt(1.0*x*x+1.0*y*y);
}
bool judge(){
	//double temp=getl(dt[0],dt[N-1]);
	double ans;
	for(int i=0;i<N;i++){
	//	if(temp!=getl(dt[i],dt[i-1]))return false;
	double temp=INF;
	int cnt=0;
	for(int j=0;j<N;j++){
			if(i==j)continue;
			if(getl(dt[i],dt[j])<temp)temp=getl(dt[i],dt[j]);
			if(i&&ans==temp)cnt++;
		}
		if(!i)ans=temp;
		//printf("%lf %d\n",ans,cnt);
		if(i)if(temp!=ans||cnt<2)return false;
	}
	
	/*double x=cross(dt[0]-dt[N-1],dt[0]-dt[1]);
	for(int i=1;i<N-1;i++){
		int y;
		if(x!=(y=cross(dt[i]-dt[i-1],dt[i]-dt[i+1]))){
			return false;
		}
	}
	if(x!=cross(dt[N-1]-dt[N-2],dt[N-1]-dt[0]))return false;*/
	return true;
}
int main(){
	int T;
	SI(T);
	T_T{
		SI(N);
		for(int i=0;i<N;i++)SL(dt[i].x),SL(dt[i].y);
		//sort(dt,dt+N,cmp);
		//for(int i=1;i<N;i++)printf("%d\n",cross(dt[i],dt[i-1]));
		if(judge())puts("YES");
		else puts("NO");
	}
	return 0;
}

  

 

Hidden String(判断正多边形)

标签:

原文地址:http://www.cnblogs.com/handsomecui/p/5023628.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!