题目链接

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. VS2010 MFC中 给菜单项添加消息响应函数

    久了没用,居然忘记了该怎样给菜单项添加响应函数了~~~~~~~~T_T 特记于此: 1. 在资源视图的Menu里找到自己要添加的菜单,然后输入菜单项. 2. 右击菜单项选属性,设置Popup为Fals ...

  2. POJ 2128:Highways

    Highways Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2730   Accepted: 1008   Specia ...

  3. Ubuntu下的计划任务 -- cron的基本知识

    下面不完全: 参考:http://blog.csdn.net/cuker919/article/details/6336457 cron是一个Linux下的后台进程,用来定期的执行一些任务.因为我用的 ...

  4. 关于阿里 weex 的使用与案例

    1. 阿里宣布开源Weex http://mp.weixin.qq.com/s?__biz=MzA4MjA0MTc4NQ==&mid=504089541&idx=1&sn=3a ...

  5. 最短路算法之 Dijkstra算法

    Dijkstra算法 Dijkstra算法是典型最短路算法,用于计算一个节点到其它全部节点的最短路径. 主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止.Dijkstra算法能得出最短路径的最 ...

  6. vue-cil 和 webpack 中本地静态图片的路径问题解决方案

    1.小于8K的图片将直接以base64的形式内联在代码中,可以减少一次http请求. 2.大于8k的呢?则直接file-loader打包, 这里并没有写明file-loader.但是确实是需要安装,否 ...

  7. linux uart驱动——相关数据结构以及API(二)

    一.核心数据结构      串口驱动有3个核心数据结构,它们都定义在<#include linux/serial_core.h>1.uart_driver     uart_driver包 ...

  8. SSH 使用密钥登录并禁止口令登录

    小结:修改下sshd配置文件,把公钥传上去就好了 先生成公钥和私钥,默认在/root/.ssh/目录,可以先看一下有没有这个目录. 生成公钥后,以后其它服务器也都可以复用这个公钥 最好生成时输入密码! ...

  9. 计算机器内存数量+引入和显示ARDS成员

    [1]README 1.1) 本代码在于读取内存中多个 内存段的地址范围描述符结构体(ARDS),有多少个内存段可以用: 1.2) source code and images in the blog ...

  10. 摩根大通银行被黑客攻克, ATM机/网银危在旦夕,winxp退市灾难来临了

    winxp4月退市到如今还不到半年,就出现故障了 7600多万个消费者银行账户被黑.此外还有700万个小企业账户的信息也被黑客窃取,这个算不算灾难呢?假设等到银行业彻底崩溃,资金彻底丧失,那不仅仅是灾 ...