题目链接:hdu_5742_It's All In The Mind

题意:

有一个部分的数列,让你找一个满足他给的三个条件的数列,使前两个数的和除这个数列的sum最大

题解:

xjb贪心一下就行了。

 #include<cstdio>
#include<cmath>
#define F(i,a,b) for(int i=a;i<=b;i++) int gcd(int a,int b){return b?gcd(b,a%b):a;} int a[],t,n,m,x,y; int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
F(i,,n)a[i]=-;
F(i,,m)scanf("%d%d",&x,&y),a[x]=y;
int sum=,pre=,zi=,gc;
for(int i=n;i>;i--)
{
if(a[i]==-)a[i]=pre;
else pre=a[i];
sum+=a[i];
}
pre=;
F(i,,)if(a[i]==-)sum+=pre,zi+=pre;
else pre=a[i],sum+=a[i],zi+=a[i];
gc=gcd(sum,zi),sum/=gc,zi/=gc;
printf("%d/%d\n",zi,sum);
}
}

hdu_5742_It's All In The Mind的更多相关文章

随机推荐

  1. Nohttp框架在Android Studio中的使用

    1.添加noHttp的使用权限 <!-- 读写 sd 卡 --> <uses-permission android:name="android.permission.REA ...

  2. openresty 前端开发轻量级MVC框架封装二(渲染篇)

    这一章主要介绍怎么使用模板,进行后端渲染,主要用到了lua-resty-template这个库,直接下载下来,放到lualib里面就行了,推荐第三方库,已经框架都放到lualib目录里面,lua目录放 ...

  3. Activity设置singleTask无法通过Intent获取值的问题

    AActivity跳转BActivity ,AActivity设置lauchmode = "SingleTask"的话,在getIntent无法获取BActivity里面的内容,无 ...

  4. USACO 1.3 Wormholes

    Wormholes Farmer John's hobby of conducting high-energy physics experiments on weekends has backfire ...

  5. ios打开系统自带APP

    打开系统自带app 打开系统设置: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root= ...

  6. 文本变语音引擎 ekho

    https://github.com/donaldlee2008/ekho https://www.oschina.net/p/ekho

  7. setTimeout 定时器用法

    setTimeout($(".msg").slideUp(5000));  msg的div 5秒往上收边 setTimeout("函数名称",1000);

  8. Computation expressions and wrapper types

    原文地址:http://fsharpforfunandprofit.com/posts/computation-expressions-wrapper-types/ 在上一篇中,我们介绍了“maybe ...

  9. 二维小波包重构wprec2\wprcoef

    clc,clear all,close all; load woman; t=wpdec2(X,2,'haar');%小波包2层分解 r_X=wprec2(t);%重构小波包 r_X10=wprcoe ...

  10. Integer.valueOf(int)及自动装箱内幕

    Integer为什么要提供功能与new Integer(xx)一样的valueOf(xx)方法呢,看了源代码之后,我发现了惊人的内幕. public static Integer valueOf(in ...