题意:有n个正方体,边长为A[i] 当A[k]-A[p]<=lim 时 k可以放在p上面,

问有多少种放法;

一开始被数据范围吓到了 ,以为是n^3算法,答案是nlogn

从小到大排序,一个一个插入,因为从小到大,所以插入一个元素时,只要管插入位置前面的元素大小关系,不用管后面的(相减一定<=0)

直接乘法原理即可

(1+k1)(1+k2).....k1即排序后 ,K[i]表示排序后 前面与A[i]相减小于lim的元素个数

#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=1111;
int n,lim;
int A[maxn];
void input()
{
for(int i=1;i<=n;i++)
scanf("%d",&A[i]);
}
void solve()
{
int ans=1;
sort(A+1,A+n+1);
for(int i=1;i<=n;i++)
{
int tot=1;
for(int j=1;j<i;j++)
{
if(A[i]-A[j]<=lim) tot++;
}
ans=(ans*tot)%10007;
}
printf("%d\n",ans);
}
void init()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
}
int main()
{
// init();
while(cin>>n>>lim)
{
input();
solve();
}
}

【巧妙思维】【4-6】Problem F的更多相关文章

  1. HDU 6324.Problem F. Grab The Tree-博弈(思维) (2018 Multi-University Training Contest 3 1006)

    6324.Problem F. Grab The Tree 题目看着好难,但是题解说的很简单,写出来也很简单.能想出来就是简单的,想不出来就难(讲道理,就算是1+1的题目,看不出来就是难的啊). 和后 ...

  2. 实验12:Problem F: 求平均年龄

    Home Web Board ProblemSet Standing Status Statistics   Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...

  3. The Ninth Hunan Collegiate Programming Contest (2013) Problem F

    Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...

  4. Codeforces Gym 100500F Problem F. Door Lock 二分

    Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...

  5. Codeforces Gym 100002 Problem F "Folding" 区间DP

    Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...

  6. Codeforces Gym 100286F Problem F. Fibonacci System 数位DP

    Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

  7. Problem F: Exponentiation

    Problem F: ExponentiationTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 4 Solved: 2[Submit][Status][W ...

  8. Problem F: 合唱比赛开始了!

    Problem F: 合唱比赛开始了! Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 440  Solved: 201[Submit][Status][ ...

  9. 几何入门合集 gym101968 problem F. Mirror + gym102082 Problem F Fair Chocolate-Cutting + gym101915 problem B. Ali and Wi-Fi

    abstract: V const & a 加速 F. Mirror 题意 链接 问题: 有n个人在y=0的平面上(及xoz平面).z=0平面上有一面镜子(边平行于坐标轴).z=a平面上有q个 ...

  10. Problem F Plug It In!

    题目链接:https://cn.vjudge.net/contest/245468#problem/F 大意:给你插座和电器的对应关系,有多个电器对应一个插座的情况,但是一个插座只能供一个电器使用,现 ...

随机推荐

  1. android安卓开发问题集 XMPP篇

    1.消息推送查了下资料,后面还是使用了androidpn (1)java.security.KeyStoreException: KeyStore jks implementation not fou ...

  2. Linux下的sudo及其配置文件/etc/sudoers的详细配置说明

    http://www.osedu.net/article/linux/2011-01-03/178.html Linux下的sudo及其配置文件/etc/sudoers的详细配置说明 1.sudo介绍 ...

  3. check cable connection PXE-M0F: Exiting intel PXE ROM no bootable device-- insert boot disk and pre

    今天修电脑遇到一个问题,新买的电脑的原装的是linux,然后我按常规方式进入PE后重装系统,然后开机一直显示下面的代码,进不去: check cable connection PXE-M0F: Exi ...

  4. hdu - 4709 - Herding

    题意:给出N个点的坐标,从中取些点来组成一个多边形,求这个多边形的最小面积,组不成多边形的输出"Impossible"(测试组数 T <= 25, 1 <= N < ...

  5. 【main()的参数探究】

    恩...今天研究信安的课件的时候看到一段对于main(int argc,char *argv[])的编程 所以探究探究main()函数的参数 探究程序如下: #include <cstdio&g ...

  6. 使用FileSystemWatcher捕获系统文件状态

    源代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sys ...

  7. DSOframer 微软官方API的查阅方法

    不了解 DSOframer 的朋友,可以先参考文章 DSOframer 的简单介绍和资源整理. 大家在使用 DSOframer 时,常常会不知道在哪里查 API 文档,网上的文章都非常零散,很难找到自 ...

  8. json输出用法+jquery validate

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx. ...

  9. PHP上传图片至阿里云

    <?php header("Content-type: text/html; charset=utf-8"); header('Access-Control-Allow-Or ...

  10. codevs1387

    题目描述                     Description 一块N x N(1<=N<=10)正方形的黑白瓦片的图案要被转换成新的正方形图案.写一个程序来找出将原始 图案按照 ...