hdu-5742 It's All In The Mind(数学)
题目链接:
It's All In The Mind
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
1. For every i∈{1,2,...,n}, 0≤ai≤100.
2. The sequence is non-increasing, i.e. a1≥a2≥...≥an.
3. The sum of all elements in the sequence is not zero.
Professor Zhang wants to know the maximum value of a1+a2∑ni=1ai among all the possible sequences.
The first contains two integers n and m (2≤n≤100,0≤m≤n) -- the length of the sequence and the number of known elements.
In the next m lines, each contains two integers xi and yi (1≤xi≤n,0≤yi≤100,xi<xi+1,yi≥yi+1), indicating that axi=yi.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=2e5+10;
const int maxn=500+10;
const double eps=1e-6; int a[maxn]; int gcd(int x,int y)
{
if(y==0)return x;
return gcd(y,x%y);
}
int main()
{
int t;
read(t);
while(t--)
{
int n,m;
read(n);read(m);
mst(a,-1);
int x,y;
For(i,1,m)
{
read(x);read(y);
a[x]=y;
}
int sum=0;
if(a[n]==-1)a[n]=0;
sum+=a[n];
for(int i=n-1;i>2;i--)
{
if(a[i]==-1)a[i]=a[i+1];
sum+=a[i];
}
if(a[1]==-1)a[1]=100;
if(a[2]==-1)a[2]=a[1];
int p,q;
p=a[1]+a[2];
q=sum+p;
//if(q==0)
int g=gcd(p,q);
cout<<p/g<<"/"<<q/g<<endl;
}
return 0;
}
hdu-5742 It's All In The Mind(数学)的更多相关文章
- HDU 5742 It's All In The Mind (贪心)
It's All In The Mind 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5742 Description Professor Zhan ...
- hdu 5742 It's All In The Mind 水题
It's All In The Mind 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5742 Description Professor Zhan ...
- HDU 5742 Chess SG函数博弈
Chess Problem Description Alice and Bob are playing a special chess game on an n × 20 chessboard. ...
- HDU 5742 It's All In The Mind (贪心) 2016杭电多校联合第二场
题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> ...
- HDU 5742 It's All In The Mind
It's All In The Mind Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- hdu 5742 It's All In The Mind(2016多校第二场)
It's All In The Mind Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- HDU - 6409:没有兄弟的舞会(数学+思维)
链接:HDU - 6409:没有兄弟的舞会 题意: 题解: 求出最大的 l[i] 的最大值 L 和 r[i] 的最大值 R,那么 h 一定在 [L, R] 中.枚举每一个最大值,那么每一个区间的对于答 ...
- HDU 6108 小C的倍数问题 【数学】 (2017"百度之星"程序设计大赛 - 初赛(A))
小C的倍数问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 3153 Pencils from the 19th Century(数学)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3153 Problem Description Before "automaton" ...
- hdu 5492 Find a path(dp+少量数学)2015 ACM/ICPC Asia Regional Hefei Online
题意: 给出一个n*m的地图,要求从左上角(0, 0)走到右下角(n-1, m-1). 地图中每个格子中有一个值.然后根据这些值求出一个最小值. 这个最小值要这么求—— 这是我们从起点走到终点的路径, ...
随机推荐
- SWF代码分析与破解之路 (YueTai VIP视频信息获取工具) Socket续篇
引言 上一篇 <Socket与站点保密应用 (隐藏链接的视频下载)>大大咧咧地从 WEB 讲 Socket.再到 TCP/IP 等协议,又再讲到 Wireshark 怎样抓IP包分析.最还 ...
- Pearson product-moment correlation coefficient in java(java的简单相关系数算法)
一.什么是Pearson product-moment correlation coefficient(简单相关系数)? 相关表和相关图可反映两个变量之间的相互关系及其相关方向,但无法确切地表明两个变 ...
- VC++的窗口句柄和窗口ID
原文地址:VC++的窗口句柄和窗口ID作者:放放 句柄是窗口资源的标识,它标识资源在系统中所占用的内存块,应用程序通过窗口句柄对窗口进行操作.除了窗口句柄之外,任何一种资源都有它自己的句柄,比如光标句 ...
- Word Ladder II——找出两词之间最短路径的所有可能
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...
- 数据结构与算法系列----AC自己主动机
一:概念 首先简要介绍一下AC自己主动机:Aho-Corasick automation,该算法在1975年产生于贝尔实验室,是著名的多模匹配算法之中的一个.一个常见的样例就是给出n个单词,再给出一段 ...
- 利用display属性写出表格的布局样式
demo地址:http://codepen.io/tianzi77/pen/gpBzjy 元素结构: <h1>display构造的table小样例,IE8及下面浏览器不支持本演示样例< ...
- ubuntu环境准备
一. 桌面方面看起来比较不爽,12的版本用起更不习惯,决定改成命令行登陆 a. vi /ect/default/grub 文件 b. 修改成第二个红框的情况 c. 执行update-grub命令 d ...
- Django小项目练习
Django学生管理系统 urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^class_list/', views.class_list ...
- webpack实用配置总结
1.webpack.config.js配置文件为: //处理共用.通用的js var webpack = require('webpack'); //处理html模板 var htmlWebpackP ...
- x264 编码数配置
记录项目中用到一组x264快速编码参数配置,具体如下: param->i_frame_reference = 1; param->i_scenecut_threshold = 0; par ...