题目大意:

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. java连接oracle数据库详细代码

    详细代码: import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;imp ...

  2. ssh 与 Telnet 的区别

    简单来书,ssh 和 telnet 是实现相同的功能 , ssh中 数据是经过加密的,是安全的 , 而 Telnet是明文传输的ssh 是加密的,基于 SSL .telnet 是明码传输的,发送的数据 ...

  3. NET基础课--异常处理X

    通常不建议如下的捕获方式  正确的方法是:某一功能函数的入口捕获基本异常即exception,分支方法或片段方法中捕获特定异常 高级: 另附:Fxcop异常监控工具

  4. android:padding和android:margin的区别

    Android的Margin和Padding跟Html的是一样的.如下图所示:黄色部分为Padding,灰色部分为Margin. 通俗的理解: Padding 为内边框,指该控件内部内容,如文本/图片 ...

  5. codeforces #330 div2

    A: #include<cstdio> #include<algorithm> #include<cmath> #include<map> #inclu ...

  6. Qt 小技巧之“To-Do 事项”

    Qt Creator 2.5 版本的时候增加了这个插件 一直没怎么用到 现在想起来 google了一下 做个总结吧 先晒图 就是这样啦 用法也很简单 在项目的随便一个位置 写一个注释 只要以上面5个关 ...

  7. php中Maximum execution time of 120 seconds exceeded时间超时错误解决方案

    1.修改php的配置文件,找到php.ini文件 max_execution_time = 120 ;//设置成你想要的值,单位是秒 2.使用ini_set()函数,使用这个函数来改变你的最大执行时间 ...

  8. 使用jquery插件uploadify上传文件的方法与疑问

    我是学生一枚,专业也不是计算机,但又要用到很多相关技术,所以在技术基础不牢靠的情况下,硬着头皮在做.最近在做一个小项目需要上传图片,而且是需要用ajax的方式.但是利用jquery的ajax方法总会有 ...

  9. easyui控件的加载顺序

    使用easyui做布局时,会模仿窗口程序界面,做出一些较复杂的布局.按由外层到内层的顺序: (最外层)panel->tabs->tabs1 ->tabs2->layout-&g ...

  10. Font Awesome 4.0.3 字体图标完美兼容IE7

    1.下载Font Awesome 4.0.3兼容包,http://www.thinkcmf.com/index.php?m=font 2.解压,并放到自己网站系统合适的位置(如果你的站已使用Font ...