前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【CodeForces 615E】Hexagons

【CodeForces 615E】Hexagons

作者头像
饶文津
发布2020-06-02 15:53:29
2450
发布2020-06-02 15:53:29
举报
文章被收录于专栏:饶文津的专栏饶文津的专栏

找规律。

代码语言:javascript
复制
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define N 10005
#define ll long long
using namespace std;
ll n,t,x,y;
ll fx[10]={1,-1,-2,-1,1,2,1};
ll fy[10]={2,2,0,-2,-2,0,2};
int main(){
    cin>>n;
    if(n==0){
        puts("0 0");
        return 0;
    }
    t=sqrt(n/3);
    while(t*(t+1)*3>=n)t--;
    x=t*2;
    y=0;
    n-=t*(t+1)*3;
    if(n){
        x+=fx[0];
        y+=fy[0];
        n--;
    }
    ll s=min(t,n);
    x+=fx[1]*s;
    y+=fy[1]*s;
    n-=s;
    
    ll d=2;
    ll dx=0,dy=0;
    t++;
    while(n>=t){
        dx+=fx[d];
        dy+=fy[d];
        d++;
        printf("%lld ",d);
        n-=t;
    }
    x+=fx[d]*n;
    y+=fy[d]*n;
    cout<<x+dx*t<<" "<<y+dy*t<<endl;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-08-05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档