栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3374 Cake Share

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3374 Cake Share

#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#include <vector>#include <queue>#define MEM(a,x) memset(a,x,sizeof a)#define eps 1e-8#define MOD 10009#define MAXN 10010#define MAXM 100010#define INF 99999999#define ll __int64using namespace std;int Read(){    char c = getchar();    while (c < '0' || c > '9') c = getchar();    int x = 0;    while (c >= '0' && c <= '9') {        x = x * 10 + c - '0';        c = getchar();    }    return x;}void Print(int a){     if(a>9)         Print(a/10);     putchar(a%10+'0');}int total,n,farey[4000000][2],all;void makefarey(int x1,int y1,int x2,int y2){    if(x1+x2>n||y1+y2>n) return;    makefarey(x1,y1,x1+x2,y1+y2);    total++;    farey[total][0]=x1+x2;    farey[total][1]=y1+y2;    makefarey(x1+x2,y1+y2,x2,y2);}int main(){    int q;    while(scanf("%d%d",&n,&q)!=EOF)    {        if(n==1)        { while(q--) {     int k;     scanf("%d",&k);     if(k==1) printf("0/1n");     else if(k==2) printf("1/1n");     else puts("No Solution"); } continue;        }        total=1;        farey[1][0]=0;        farey[1][1]=1;        makefarey(0,1,1,2);        farey[total+1][0]=1;        farey[total+1][1]=2;        all=total*2+1;        while(q--)        { int k; scanf("%d",&k); if(k>all) puts("No Solution"); else if(k<=total+1) printf("%d/%dn",farey[k][0],farey[k][1]); else printf("%d/%dn",farey[all-k+1][1]-farey[all-k+1][0],farey[all-k+1][1]);        }    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/376137.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号