HDU 5521 Pagodas

2015 ACM / ICPC 沈阳现场赛 D 题

找了一小时规律......发现是个GCD。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;

int n,a,b;

int gcd(int a,int b)
{
    int t;
    while(b) t = a%b,a = b,b = t;
    return a;
}

int main()
{
    int T;
    scanf("%d",&T);
    for(int Case=1; Case<=T; Case++)
    {
        scanf("%d%d%d",&n,&a,&b);
        printf("Case #%d: ",Case);
        if((n/gcd(a,b)-2)%2==0) printf("Iaka\n");
        else printf("Yuwgna\n");
    }
    return 0;
}
时间: 2024-11-10 10:03:51

HDU 5521 Pagodas的相关文章

hdu 5521 最短路

Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1656    Accepted Submission(s): 515 Problem Description Bessie and her friend Elsie decide to have a meeting. However, after Farmer Joh

HDU 5521 Meeting(虚拟节点+最短路)

Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1358    Accepted Submission(s): 435 Problem Description Bessie and her friend Elsie decide to have a meeting. However, after Farmer Jo

HDU 5521.Meeting 最短路模板题

Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 3361    Accepted Submission(s): 1073 Problem Description Bessie and her friend Elsie decide to have a meeting. However, after Farmer Jo

Hdu 5521 Meeting(建图+最短路)

题目地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=5521 思路:边数太多,不能直接建图.对于每个集合,设置一个虚拟点,对于每个集合中的点u:连一条u->S权值为0的边(点在集合中,花费为0):连一条S->u权值为w的边(从集合中一点到另一点花费w).分别计算从点1到i和从点n到i的最短路,枚举i,则ans=min( ans,max ( dist[0][i],dist[1][i] ) ). #include<queue> #i

【hdu 5521】【 2015ACM/ICPC亚洲区沈阳站重现赛】Meeting 题意&题解&代码

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5521 题意: 输入:输入n表示有n个点,输入m表示有m个点集. 接下来m行信息,每行先输入一个t表示这个点集中任意两点费时为t,再输入一个s,表示有s个点在这个点集中,接下来s个数表示这些数在这个点集之中. 现在有两个人,其中一个人住在点1,另一个人住在点n,如果两个人要见面,同时出发,可以走走停停,问需要最少时间是多少,有哪几个点能被当成见面点. 题解: 我们发现这道题如果建好图之后就直接是一个

hdu 5521 Meeting(最短路)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 题意:有1-n共n个点,给出m个块(完全图),并知道块内各点之间互相到达花费时间均为ti.已知两人分别在点1和点n,求在哪些点相遇能使得花费时间最短.题解:显然先想到从点1和点n分别求最短路,然后枚举点找出哪些点是相遇花费时间最少的.但是这题边太多了,假设一个完全图里有x个点,那边就有x*(x-1)/2条了,必须化简其边.一个可行的办法是给每个完全图增加两个点,分别为入点和出点,入点向其中的点

HDU - 5512 Pagodas

n pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, labelled from 1 to n. However, only two of them (labelled a and b, where 1≤a≠b≤n) withstood the test of time. Two monks, Yuwgna and Iaka, decide to mak

HDU 5521 题解

题意:给出n个点,John需要和一个住在第n个点的人在某个点碰面,再给出m个集合,每个集合中包含Si个点,这些点两两之间可以以ti时间互达,求两人需花费的最小时间,若无法走到第n个点,则输出Evil John. 2<=N<=100000;1<=ti<=1e9;Si>0;∑Si<=1e6; 共1~6组数据,6000MS 算法/思路: 第一次见到这种套路的话还是蛮有趣的,对每个集合中两两点建边显然会被轻松TLE. 使用最短路+虚拟节点:于是我们对每个集合建立一个虚拟节点,在

HDU 5521 Meeting

每个点向他所在集合连一条权为0的边,每个集合向他里面所有点连一条权为c的边,跑最短路就行了. #include <bits/stdc++.h> using namespace std; #define prt(k) cerr<<#k" = "<<k<<endl typedef long long LL; //const int inf = 0x3f3f3f3f; const int M = 2000100; const LL inf =