题目大意:

yuebai has a long sequence of integers A1,A2,…,AN.

He also has such a function:

F(x)=∑i=1N(⌊Aix⌋+Aimodx)

x is
a positive integer, which determined by yuebai.

Now he wants to know the minimum value of the function.

求一个x 使F[x]最大

解:

从1枚举到10^6

可知 当X超过10^6 方后 值就不变了

SB了

以为能快速求出的是sigma(Aimodx)。。。

发现 傻逼了 能快速求出的事 sigma(Aimodx)modx。。

预处理好a[i] 表示 A[i]中数值小于i的个数

以N/X的时间求出sigmafloor((Ai/x));

然后利用sigmafloor((Ai/x))+sigma(Aimodx)=sigma(Ai) 求出 sigma(Aimodx)

然后更新答案

代码如下:

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#define oo 0x13131313
using namespace std;
const int maxn=1000000+5;
int N;
int A[maxn],a[maxn];
int MAX;
long long sum=0;
void input()
{
memset(A,0,sizeof(A));
memset(a,0,sizeof(a));
cin>>N;
MAX=-1;
sum=0;
for(int i=1;i<=N;i++)
{
scanf("%d",&A[i]);
a[A[i]]++;
if(A[i]>MAX) MAX=A[i];
sum+=A[i];
}
for(int i=1;i<=MAX;i++)
{
a[i]=a[i]+a[i-1];
}
}
void solve()
{
long long ans=1LL<<30;
long long tt=0,g;
for(int i=1;i<=MAX;i++)
{
int x=i;tt=0;
for(int t=2*x;t-1<=MAX;t+=x)
{
int p=t-1;
long long k=(long long)(a[p]-a[p-x])*(long long)(p/x);
tt=tt+k;
g=p;
}
tt=tt+(long long)(a[MAX]-a[g])*(long long)(MAX/x);
tt=tt+sum-tt*(long long)x;
if(tt<ans) ans=tt;
}
cout<<ans<<endl;
}
int main()
{
// freopen("a.in","r",stdin);
int T;
cin>>T;
while(T--)
{
input();
solve();
}
}

【数学水题】【TOJ4113】【 Determine X】的更多相关文章

  1. 天哪!毫无思绪!令人感到恐惧的数学(水题?)(TOWQs)

    这道题的题目描述灰常简单,第一眼看以为是一道十分水的题目: 但是!!!(我仔细一看也没有发现这背后隐藏着可怕的真相~) 下面给出题目描述: 给出一个整数x,你可以对x进行两种操作.1.将x变成4x+3 ...

  2. hdu 2710 Max Factor 数学(水题)

    本来是不打算贴这道水题的,自己却WA了三次.. 要考虑1的情况,1的质因子为1 思路:先打表 ,然后根据最大质因子更新结果 代码: #include<iostream> #include& ...

  3. ZOJ 1494 Climbing Worm 数学水题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=494 题目大意: 一只蜗牛要从爬上n英寸高的地方,他速度为u每分钟,他爬完u需要 ...

  4. HDU 1840 Equations (简单数学 + 水题)(Java版)

    Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1840 ——每天在线,欢迎留言谈论. 题目大意: 给你一个一元二次方程组,a(X^2 ...

  5. lightoj 1148 Mad Counting(数学水题)

    lightoj 1148 Mad Counting 链接:http://lightoj.com/volume_showproblem.php?problem=1148 题意:民意调查,每一名公民都有盟 ...

  6. zzulioj--1790-- 弹珠游戏(数学水题!)

    弹珠游戏 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 14  Solved: 10 SubmitStatusWeb Board Descriptio ...

  7. zzulioj--1841--so easy!麻麻再也不用担心我的数学了!(数学水题)

    1841: so easy!麻麻再也不用担心我的数学了! Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 27  Solved: 15 SubmitSt ...

  8. HDU 1408 盐水的故事 数学水题

    http://acm.hdu.edu.cn/showproblem.php?pid=1408 题目: 挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下:然后滴二滴,停一下:再滴三滴,停一下...,现 ...

  9. 【Comet OJ - Contest #0 A】解方程(数学水题)

    点此看题面 大致题意: 给定自然数\(n\),让你求出方程\(\sqrt{x-\sqrt n}+\sqrt y-\sqrt z=0\)的自然数解\(x,y,z\)的数量以及所有解\(xyz\)之和. ...

随机推荐

  1. hdu 3681 Prison Break(状态压缩+bfs)

    Problem Description Rompire . Now it’s time to escape, but Micheal# needs an optimal plan and he con ...

  2. struts2采用convention-plugin实现零配置

    最近开始关注struts2的新特性,从这个版本开始,Struts开始使用convention-plugin代替codebehind-plugin来实现struts的零配置. 配置文件精简了,的确是简便 ...

  3. 【剑指Offer学习】【面试题60:把二叉树打印出多行】

    题目:从上到下按层打印二叉树,同一层的结点按从左到右的顺序打印,每一层打印一行. 解题思路 用一个队列来保存将要打印的结点.为了把二叉树的每一行单独打印到一行里,我们须要两个变量:一个变量表示在当前的 ...

  4. stagefright框架(六)-Audio Playback的流程

    到目前为止,我们都只着重在video处理的部分,对于audio却只字未提.这篇文章将会开始audio处理的流程. Stagefright中关于audio的部分是交由AudioPlayer来处理,它是在 ...

  5. MVC 授权过滤器 AuthorizeAttribute

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  6. C语言-数据的快速引用

    1.常量:程序运行中,不会改变 整形常量 实形常量 字符常量:使用单引号引起的单个字符或者转移字符 ‘a’ 字符串常量:使用双引号引起的单个或者多个字符序列 "ab",存储的时候, ...

  7. div+css+javascript 走马灯图片轮换显示

    效果如图 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

  8. $digest already in progress

    最近在写项目时经常遇到一个小问题,在上下文外改变视图,通常来说我们需要apply()便可以实现,问题是加了apply()后控制台报错:$digest already in progress:随后我把a ...

  9. 关于php输入$_post[‘’]报错的原因

    在php中输入$_post[‘’]值时页面报错,是因为变量未声明,所以页面出现提示Undefined index,是因为首先要用isset来判断是否存在这个变量. 如:isset($_POST['/* ...

  10. Ubuntu配置OpenGL环境

    建立基本编译环境 sudo apt-get install build-essential 安装OpenGL Library sudo apt-get install libgl1-mesa-dev ...