题目链接

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1504

题意

给出一串字符串 里面的每个字符的位置 都按照题目的意思 给出

求哪些字母 所在的位置 随意三个点 是否能构成 一个 正三角形 如果能 就输出这个字母 最后输出的结果 要按照字典序

思路

难点在于 给这些字母赋予坐标

我们可以从最底层 来赋值

最底层的 Y坐标都是1 X坐标分别是 `1, 2, 3, 4

然后往上走 的坐标 都是右 下一层的两个坐标决定的

X的坐标 是 下一层两个坐标的终点 Y坐标是下面一层坐标Y坐标+ sqrt(3)/2

数据范围很小 用 O(n^3) 暴力 都是可以过的

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a, b) memset(a, (b), sizeof(a))
#define pb push_back using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss; const double PI = acos(-1.0);
const double E = exp(1.0);
const double eps = 1e-8; const int INF = 0x3f3f3f3f;
const int maxn = 4e5 + 5;
const int MOD = 1e9 + 7; struct node
{
double x, y;
int c;
}q[12][12]; double dis(node a, node b)
{
double ans = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
return ans;
} bool EPS(double x, double y)
{
if (fabs(x - y) < eps)
return true;
return false;
} bool equil(node a, node b, node c)
{
double Dis1 = dis(a, b);
double Dis2 = dis(a, c);
double Dis3 = dis(b, c);
if (EPS(Dis1, Dis2) && EPS(Dis1 , Dis3) && EPS(Dis2, Dis3))
return true;
return false;
} int main()
{
int n;
while (scanf("%d", &n) && n)
{
string s;
cin >> s;
int len = s.size();
vector <node> c[26];
CLR(q, 0);
for (int i = 0, count = 0; i < n; i++)
{
for (int j = 0; j < i + 1; j++)
{
q[i][j].c = s[count++] - 'a';
}
}
for (int i = 0; i < n; i++)
{
q[n - 1][i].x = i + 1;
q[n - 1][i].y = 1;
c[q[n - 1][i].c].pb(q[n - 1][i]);
}
for (int i = n - 2; i >= 0; i--)
{
for (int j = 0; j <= i; j++)
{
q[i][j].y = q[i + 1][j].y + sqrt(3.0) * 1.0 / 2;
q[i][j].x = (q[i + 1][j].x + q[i + 1][j + 1].x) * 1.0 / 2;
c[q[i][j].c].pb(q[i][j]);
}
}
string ans = "";
for (int l = 0; l < 26; l++)
{
int len = c[l].size();
int flag = 0;
for (int i = 0; i < len; i++)
{
for (int j = 0; j < len; j++)
{
for (int k = 0; k < len; k++)
{
if (i != j && i != k && j != k && flag == 0)
{
if (equil(c[l][i], c[l][j], c[l][k]))
{
ans += l + 'a';
flag = 1;
}
}
}
}
}
}
if (ans == "")
printf("LOOOOOOOOSER!\n");
else
cout << ans << endl;
}
}

最新文章

  1. call,apply,bind
  2. First Blog
  3. MAC OS terminal 快捷键记录
  4. Snort - 配置文件
  5. 【原创】Windows Server 文件夹权限小问题
  6. Bootstrap系列 -- 16. 文本域textarea
  7. js的一个稍微高级点的用法
  8. Java 多线程编程之九:使用 Executors 和 ThreadPoolExecutor 实现的 Java 线程池的例子
  9. Oracle SQL 关键字
  10. Android handler 可能会造成内存泄露
  11. JavaScript中的数组对象遍历、读写、排序等操作
  12. K-means算法的matlab程序
  13. SpringBoot 之热部署
  14. npm构建保存 code ELIFECYCLE解决办法
  15. Socket(转自 阿里云)
  16. Windows下的包管理器Chocolatey的使用
  17. vue 中view层中方法的使用
  18. Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)?
  19. java判断字符串是否为数字,包括负数
  20. 51Nod1053 最大M子段和V2 二分+DP

热门文章

  1. 如何判断自己外网IP是否为真实公网IP,以及解决方案
  2. Drawable 添加过滤色,改变图片颜色
  3. TOYS-POJ2318
  4. linux 打开文件数too many open files解决方法
  5. java中的占位符\t\n\r\f
  6. 微信小程序 - 考试倒计时
  7. HTML5 Support In Visual Studio 2010
  8. vs2010 assistx安装教程
  9. UML--组件图,部署图
  10. Lua学习一----------开发环境搭建