【巧妙思维】【4-6】Problem F
题意:有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的更多相关文章
- HDU 6324.Problem F. Grab The Tree-博弈(思维) (2018 Multi-University Training Contest 3 1006)
6324.Problem F. Grab The Tree 题目看着好难,但是题解说的很简单,写出来也很简单.能想出来就是简单的,想不出来就难(讲道理,就算是1+1的题目,看不出来就是难的啊). 和后 ...
- 实验12:Problem F: 求平均年龄
Home Web Board ProblemSet Standing Status Statistics Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...
- 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 ...
- Codeforces Gym 100500F Problem F. Door Lock 二分
Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...
- Codeforces Gym 100002 Problem F "Folding" 区间DP
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...
- 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 ...
- Problem F: Exponentiation
Problem F: ExponentiationTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 4 Solved: 2[Submit][Status][W ...
- Problem F: 合唱比赛开始了!
Problem F: 合唱比赛开始了! Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 440 Solved: 201[Submit][Status][ ...
- 几何入门合集 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个 ...
- Problem F Plug It In!
题目链接:https://cn.vjudge.net/contest/245468#problem/F 大意:给你插座和电器的对应关系,有多个电器对应一个插座的情况,但是一个插座只能供一个电器使用,现 ...
随机推荐
- (十)boost库之多线程
(十)boost库之多线程 1.创建线程 使用boost库可以方便的创建一个线程,并提供最多支持9个参数的线程函数,相对于void*来说,方便了很多,创建线程主要提供了一下3种方式: 线程库头文件:# ...
- JavaEE Tutorials (25) - 使用Java EE拦截器
25.1拦截器概述380 25.1.1拦截器类381 25.1.2拦截器生命周期381 25.1.3拦截器和CDI38125.2使用拦截器381 25.2.1拦截方法调用382 25.2.2拦截生命周 ...
- 新 Azure SQL 数据库服务等级的性能
4 月 24 日,我们发布了 SQL Database 基本级(预览版)和标准级(预览版)新服务等级的预览版以及新的业务连续性功能.在本博客文章中,我们将深入探究 SQL Database 中新等级的 ...
- chrome console 调试xpath
chrome console F12->$x(“//title”) [<title>Online Tools for Software Developers (Free)</t ...
- IOS设备设计完整指南(转载)
http://blog.sina.com.cn/s/blog_6cc9af670102vq12.html
- 灵活使用getconf命令来获取系统信息
http://blog.chinaunix.net/uid-23105261-id-109513.html 灵活使用getconf命令来获取系统信息 我们时常需要查询系统相关的信息,比如页面大小,整数 ...
- Object-c 单例模式中的 allocWithZone作用
最 近因为在ios应用开发中,考虑到一些公共方法的封装使用,就决定使用单例模式的写法了..不知道,Object-c中的单例模式的写法是否和java中的写法是否有所区别? 于是阿堂从网上一搜,发现“ O ...
- A. Anton and Letters
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 不使用TNS直连数据库的三种方式
1.在当前目录下新建tnsnames.ora文件 如windows环境下,在C:\Users\Administrator目录下新建tnsnames.ora文件,内容如下:test =(descript ...
- PictureBox从本地上传图片和保存在磁盘目录
private void mypicbox_Click(object sender, EventArgs e) { try { OpenFileDialog ofdPic = new OpenFile ...