题意:

给出n和m,表示n个数,之后会给出m个下标xi和值yi,a[xi]=yi,n个数是不下降的,且总和>0,要使得(x1+x2)/∑(xi)最大。


分析:

尽可能使得前两个数最大,其他数尽可能小即可。


代码:


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, a, b) for (int i(a); i <= (b); ++i)
int a[];
int
T;
int
n, m, x1,x2, y1,y2; inline int gcd(int a, int b){return b == ? a : gcd(b, a % b);} int main(){
scanf("%d ", &T);
loop: while (T--){
scanf("%d %d ", &n, &m);
memset(a,, sizeof a);
x1=;
scanf("%d %d",&x2,&y2);
if
(x2==)
{

a[]=a[]=y2;x1=x2;
}

else

{

a[x2]=y2;
if
(x2<=) rep(i,,x2-) a[i]=;
else
{a[]=a[]=;rep(i,,x2-) a[i]=y2;} x1=x2;
}

rep(i,,m)
{

scanf("%d %d", &x2, &y2);
a[x2]=y2;
if
(i<=m)
{

if
(x1+==) rep(j,,x2-) a[j]=y2;
else
rep(j,x1+,x2-) a[j]=y2;
}

x1=x2;
}

rep(j,x1+,n) a[j]=;
//rep(i,1,n) printf("a[%d]=%d\n",i,a[i]);
if (n ==){ puts("1/1"); goto loop;}
int
sum =;
rep(i,, n) sum += a[i];
//printf("a[1]+a[2]=%d sum=%d\n",a[1]+a[2],sum);
int g = gcd(a[]+a[], sum);
printf("%d/%d\n", (a[]+a[])/ g, sum / g);
}

return
;
}
 

HDU5742:It's All In The Mind(模拟+贪心 )的更多相关文章

  1. BZOJ1029: [JSOI2007]建筑抢修[模拟 贪心 优先队列]

    1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec  Memory Limit: 162 MBSubmit: 3785  Solved: 1747[Submit][Statu ...

  2. Codeforces Round #375 (Div. 2) A B C 水 模拟 贪心

    A. The New Year: Meeting Friends time limit per test 1 second memory limit per test 256 megabytes in ...

  3. Codeforces 452D [模拟][贪心]

    题意: 给你k件衣服处理,告诉你洗衣机烘干机折叠机的数量,和它们处理一件衣服的时间,要求一件衣服在洗完之后必须立刻烘干,烘干之后必须立刻折叠,问所需的最小时间. 思路: 1.按照时间模拟 2.若洗完的 ...

  4. BZOJ_1028_[JSOI2007]_麻将_(模拟+贪心)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1028 同一种花色的牌,序数为\(1,2,...,n\).定义"和了"为手上 ...

  5. Educational Codeforces Round 63 (Rated for Div. 2) B. Game with Telephone Numbers 博弈思维+模拟+贪心思维

    题意:博弈题面  给出一个数字序列 (>=11)  有两个人任意删除数字 直到 数字只剩下11位 如果删除后的数字串开头是8那么就是第一个赢 否则就是第二个人赢 第一个人先手  数字序列一定是奇 ...

  6. NOIP模拟题 2017.7.3 - 模拟 - 贪心 - 记忆化搜索

    直接暴力模拟,注意判数据结构为空时的取出操作. Code #include<iostream> #include<cstdio> #include<ctime> # ...

  7. Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟 贪心

    C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. bzoj 2457 [BeiJing2011]双端队列 模拟+贪心

    [BeiJing2011]双端队列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 457  Solved: 203[Submit][Status][D ...

  9. Codeforces Round #482 (Div. 2) B、Treasure Hunt(模拟+贪心)979B

    题目 大致题意 n表示要进行n次操作,接着给出三个字符串,表示三个人初始拥有的串.每次操作要替换字符串中的字母,询问最后在游戏中曾出现过的相同的子串谁最多. 思路 (1)  讨论最多的子串,肯定是全部 ...

随机推荐

  1. Ossec常用命令

    启动并查看httpd服务 systemctl start httpd systemctl status httpd.service 启动并查看mysql服务 systemctl start maria ...

  2. makefile生成静态库和动态库

    库是一种软件组件技术,库里面封装了数据和函数. 库的使用可以使程序模块化. Windows系统包括静态链接库(.lib文件)和动态链接库(.dll文件). Linux通常把库文件存放在/usr/lib ...

  3. Java解压上传zip或rar文件,并解压遍历文件中的html的路径

    1.本文只提供了一个功能的代码 public String addFreeMarker() throws Exception { HttpSession session = request.getSe ...

  4. NFC(4)响应NFC设备时启动activity的四重过滤机制

    响应NFC设备时启动activity的四重过滤机制 在一个NFC设备读取NFC标签或另一个NFC设备中的数据之前会在0.1秒之内建立NFC连接,然后数据会自动从被读取一端流向读取数据的一端(NFC设备 ...

  5. Android权限安全(6)四大组件自定义权限示例

    Activity service ContentProvider BroadcastReceiver

  6. [Codeforces673B]Problems for Round(思路,规律)

    题目链接:http://codeforces.com/contest/673/problem/B 现在有n个题和m个相似的关系,现在要把他们分到2组去. 要求: 1组的所有题比2组难 每个组都得至少有 ...

  7. BZOJ_1024_[SHOI2008]_生日快乐_(dfs)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1024 给出一个\(x*y\)的距形,要求平行于边切,最终切成\(n\)个面积相等的小距形,求长 ...

  8. sql字符串函数(转)

    计算字符串长度 len()用来计算字符串的长度 select sname ,len(sname) from student 字符串转换为大.小写 lower() 用来将一个字符串转换为小写,upper ...

  9. [POJ 3498] March of the Penguins

    March of the Penguins Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 4378   Accepted:  ...

  10. Linux find xargs rm .orig

    /********************************************************************* * Linux find xargs rm .orig * ...