HDU5742:It's All In The Mind(模拟+贪心 )
题意:
给出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(模拟+贪心 )的更多相关文章
- BZOJ1029: [JSOI2007]建筑抢修[模拟 贪心 优先队列]
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MBSubmit: 3785 Solved: 1747[Submit][Statu ...
- 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 ...
- Codeforces 452D [模拟][贪心]
题意: 给你k件衣服处理,告诉你洗衣机烘干机折叠机的数量,和它们处理一件衣服的时间,要求一件衣服在洗完之后必须立刻烘干,烘干之后必须立刻折叠,问所需的最小时间. 思路: 1.按照时间模拟 2.若洗完的 ...
- BZOJ_1028_[JSOI2007]_麻将_(模拟+贪心)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1028 同一种花色的牌,序数为\(1,2,...,n\).定义"和了"为手上 ...
- Educational Codeforces Round 63 (Rated for Div. 2) B. Game with Telephone Numbers 博弈思维+模拟+贪心思维
题意:博弈题面 给出一个数字序列 (>=11) 有两个人任意删除数字 直到 数字只剩下11位 如果删除后的数字串开头是8那么就是第一个赢 否则就是第二个人赢 第一个人先手 数字序列一定是奇 ...
- NOIP模拟题 2017.7.3 - 模拟 - 贪心 - 记忆化搜索
直接暴力模拟,注意判数据结构为空时的取出操作. Code #include<iostream> #include<cstdio> #include<ctime> # ...
- 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 ...
- bzoj 2457 [BeiJing2011]双端队列 模拟+贪心
[BeiJing2011]双端队列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 457 Solved: 203[Submit][Status][D ...
- Codeforces Round #482 (Div. 2) B、Treasure Hunt(模拟+贪心)979B
题目 大致题意 n表示要进行n次操作,接着给出三个字符串,表示三个人初始拥有的串.每次操作要替换字符串中的字母,询问最后在游戏中曾出现过的相同的子串谁最多. 思路 (1) 讨论最多的子串,肯定是全部 ...
随机推荐
- Tomcat下的一些配置
1. JAVA虚拟机性能优化,修改bin下的 catalina.sh/bat rem ----- Execute The Requested Command -------------------- ...
- C语言中的宏展开
#include<stdio.h> #define f(a,b) a##b #define g(a) #a #define h(a) g(a) int main() { printf(,) ...
- Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.解决办法
刚刚更新AS到2.0版本,然后导入Api Demos的时候出现了这个错误. 解决办法:在AS的菜单栏,Tools->Android ->Enable ADB integration 勾选就 ...
- C++ STL之查找算法
C++STL有好几种查找算法,但是他们的用法上有很多共同的地方: 1.除了binary_search的返回值是bool之外(查找的了返回true,否则返回false),其他所有的查找算法返回值都是一个 ...
- js实现ppt
实现ppt的js框架有很多,这里推荐几个: impress.js impress.js demo webSlide.js webSlide.js demo reveal.js ...
- 宏HASH_GET_FIRST
/*******************************************************************//** Gets the first struct in a ...
- ASP.NET MVC Html.BeginForm用法1
Html.BeginForm():该方法用于构建一个From表单的开始, 他的构造方法为:Html.BeginForm("ActionName","ControllerN ...
- asp.net实现GZip压缩和GZip解压
最近在开发一个网站doc.115sou.com,使用到了GZip压缩技术,经过多次搜索找到asp.net中用GZip对数据压缩和解压缩非常方便,当我第一次拿到这个类的时候却感觉很迷茫,无从下手.主要是 ...
- POJ 3469 Dual Core CPU (最小割建模)
题意 现在有n个任务,两个机器A和B,每个任务要么在A上完成,要么在B上完成,而且知道每个任务在A和B机器上完成所需要的费用.然后再给m行,每行 a,b,w三个数字.表示如果a任务和b任务不在同一个机 ...
- 【Java学习笔记】Hello world
package aaa; public class aaa { public static void main(String args[]){ System.out.println("hel ...