题目链接: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. android 实现透明状态栏

    主要使用https://github.com/jgilfelt/SystemBarTint这个开源库 1 ,导入SystemBarTintManager类 2 ,BaseFragmentActivit ...

  2. 湖南多校对抗赛(2015.05.03)Problem B: War

    并查集.从后往前加边. #include<stdio.h> #include<string.h> #include<math.h> #include<algo ...

  3. Cells(Rows.Count, 1).End(xlUp).Row的含义

     NextRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1     这句话的意思是 取活动单元表的第一列最后一个有值的行的下一行行号. ...

  4. 如何使用cygwin去编译cocos2dx项目中的C++文件

    将生成的cocos2dx的Android项目导入到eclipse 可以先测试一下如何编译C++项目: 1.打开cygwin,进入到Android项目对应的目录下面去: 2.编译脚本 在编译脚本之间,如 ...

  5. Python学习笔记_Chapter 6定制数据对象

    1. 有用的BIF a. 判断字符串中是否包含子字符串 if s_a in s_b: b. pop() 描述:从指定的列表位置删除并返回一个数据项. (sarah_name,sarah_dob)=l_ ...

  6. hdu_4417_Super Mario(主席树)

    题目链接:hdu_4417_Super Mario 题意: 给你n个树,有m个询问,每个询问有一个区间和一个k,问你这个区间内不大于k的数有多少个. 题解: 考虑用主席树的话就比较裸,当然也可以用其他 ...

  7. MATLAB制作符合IEEE标准的图插入Latex

    1.MATLAB最好保存为eps格式,虽然IEEE也支持png等其他格式,但是MATLAB在保存为png格式时,很容易在后期插图时,出现分辨率不足等问题. 2. MATLAB在save as图片的时候 ...

  8. Binary Trees

    1. Definiation What is Binary Trees? Collection of node (n>=0) and in which no node can have more ...

  9. linux命令 time

    功能:用于计算命令执行的世界 语法:  time command 例如: hbg@root:~/dl$ time ls111     apple.sh  b.txt            duplic ...

  10. Android 安装镜像

    1. 关机 2. 按住音量减键和电源键,直到进入fastboot模式 3. 连接上PC 4. PC端输入sudo fastboot devices验证已识别到设备 5. PC端输入sudo fastb ...