题目链接

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;
}
}

ZOJ - 1504 Slots of Fun 【数学】的更多相关文章

  1. zoj 1028 Flip and Shift(数学)

    Flip and Shift Time Limit: 2 Seconds      Memory Limit: 65536 KB This puzzle consists of a random se ...

  2. ZOJ 2679 Old Bill(数学)

    主题链接:problemCode=2679" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProbl ...

  3. ZOJ 2680 Clock()数学

    主题链接:problemId=1680" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProblem ...

  4. zoj 2722 Head-to-Head Match(数学思维)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2722 题目描述: Our school is planning ...

  5. ZOJ 3203 Light Bulb(数学对勾函数)

    Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...

  6. ZOJ - 3866 Cylinder Candy 【数学】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3866 思路 积分 参考博客 https://blog.csdn. ...

  7. ZOJ - 3993 - Safest Buildings (数学)

    参考:https://blog.csdn.net/KuHuaiShuXia/article/details/78408194 题意: 描述了吃鸡刷圈的问题,给出楼的坐标点,和两次刷圈的半径R和r,现在 ...

  8. ZOJ 3819 Average Score(数学 牡丹江游戏网站)

    主题链接:problemId=5373">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 Bob is ...

  9. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

随机推荐

  1. DEDECMS图片集上传图片出错302的解决办法

    无忧主机(www.51php.com)小编今天在调试dede网站的时候发现了一个问题,因为小编想在网站上增加一个图片集的栏目,于是就到后台图片集栏目去添加内容,谁知在上传图片的时候给我弹出个错误信息框 ...

  2. 使用Powermock和mockito来进行单元测试

    转载:http://blog.csdn.net/u013428664/article/details/44095889 简介 Mockito是一个流行的Mocking框架.它使用起来简单,学习成本很低 ...

  3. blind xxe攻击

    最近做啊里的题的时候遇到了 http://hivesec.net/web-security/%E5%85%B3%E4%BA%8Eblind-xxe.html

  4. Foreach嵌套Foreach速度慢优化方案

    有时候这样的效率还可以,但是只要牵涉到操作数据库,那就GAMEOVER.. 最近在维护项目,一个Foreach循环,4分半才能出来结果. 代码: foreach ($content as $key = ...

  5. 【C语言学习】封装和模块化思想

    刚学习完C后,做的关于C的课程设计是在一个源文件里放了几百行代码,并且各个功能之间都是相互依赖的,这样就会非常麻烦. 由于当我要改动某个地方的时候,就会牵连着要改动喝多的地方.而在实际的程序设计中.这 ...

  6. Android---61---TabHost简单使用

    与TabHost结合使用的组件: TabWidget:代表选项卡的标签条 TabSpec:代表选项卡的一个Tab页面 TabHost不过一个简单的容器,它提供两个方法来创建.加入选项卡 newTabS ...

  7. android开发笔记之fastboot的使用

    fastboot命令大全 在终端中.我们输入: fastboot 对于这些命令.我不解释,慢慢使用.慢慢的就会明确是怎么回事了. android分区 分区 作用 splash1 开机画面.使用Nand ...

  8. Controller层返回字符串

    刚开始练习,有时候想让Controller层返回一个字符串,但是他却去寻找这个字符串名字的jsp页面,结果肯定会是404的,研究了一会才明白过来,如果Controller需要返回一个值的话,需要再方法 ...

  9. cmake学习之-project

    一.系统版本 cmake version: 3.5.2 系统版本: Ubuntun 16.04 cmake docment: 3.14.4 最后更新: 2019-05-31 二.指令说明 projec ...

  10. 关于C++项目指针对象未被初始化的问题(0xcdcdcd)

    http://blog.csdn.net/devfun/article/details/6900086 昨天我试图将一个封装好的模块加入到正在开发的项目中,这个模块不是单独的类,而且对应的声明和实例. ...