ZOJ - 1504 Slots of Fun 【数学】
题目链接
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 【数学】的更多相关文章
- zoj 1028 Flip and Shift(数学)
Flip and Shift Time Limit: 2 Seconds Memory Limit: 65536 KB This puzzle consists of a random se ...
- ZOJ 2679 Old Bill(数学)
主题链接:problemCode=2679" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProbl ...
- ZOJ 2680 Clock()数学
主题链接:problemId=1680" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProblem ...
- zoj 2722 Head-to-Head Match(数学思维)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2722 题目描述: Our school is planning ...
- ZOJ 3203 Light Bulb(数学对勾函数)
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- ZOJ - 3866 Cylinder Candy 【数学】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3866 思路 积分 参考博客 https://blog.csdn. ...
- ZOJ - 3993 - Safest Buildings (数学)
参考:https://blog.csdn.net/KuHuaiShuXia/article/details/78408194 题意: 描述了吃鸡刷圈的问题,给出楼的坐标点,和两次刷圈的半径R和r,现在 ...
- ZOJ 3819 Average Score(数学 牡丹江游戏网站)
主题链接:problemId=5373">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 Bob is ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
随机推荐
- PHP设置头部编码为UTF-8语句
header("Content-type: text/html; charset=utf-8");
- implement-stack-using-queues(easy,但也有思考价值)
https://leetcode.com/problems/implement-stack-using-queues/ 还有种方法,就是利用同一个队列,知道队列长度前提下,把内容从头到尾,再向尾部依次 ...
- MFC 消息类型
标准(窗口)消息:窗口消息一般与窗口内部运作有关,如创建窗口,绘制窗口,销毁窗口,通常,消息是从系统发到窗口,或从窗口发到系统.发送函数SendMessage()或者PostMessage().除WM ...
- 【前端阅读】——《JavaScript入门经典》摘记之JavaScript与XML
前言:这本书除了基础的JavaScript理论体系之外,有一个特别的章节,就是讲解——JavaScript与XML的关系,从中,我更进一步的了解了XML的基础.创建.显示以及使用JavaScript如 ...
- thinkphp5 中使用postgresql 缺少函数 table_msg
参考解决办法 在postgresql 中执行命令 插入函数 https://blog.csdn.net/sinat_35767703/article/details/76070236?utm_sour ...
- UDP最大传输字节
每个包最大可携带字节长度:65507个byte. 封装成 IP 后,大小超出 PMTU 的分组将可能被 fragmented. 如果设置了 Don't Frag,超出 PMTU 的分组将不能被发送. ...
- Ubuntu安装vncserver实现图形化远程桌面
安装 apt-get update apt-get install vnc4server 开启vnc服务 vncserver 首次启动会要求设置密码,后面可以使用vncpasswd修改: 看到 New ...
- iPhone X
iPhone X前置深度摄像头带来了Animoji和face ID,同时也将3D Face Tracking的接口开放给了开发者.有幸去Cupertino苹果总部参加了iPhone X的封闭开发,本文 ...
- 制作个人开发IDE
1.打开VS2013,新建项目: 2.点击下一步,下一步.到达例如以下界面: 3.下一步 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3R ...
- Proving Equivalences (hdu 2767 强联通缩点)
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...