【Codeforces 788C】The Great Mixing
http://codeforces.com/contest/788/problem/C
显然如果有两杯一样的酒,把它们当作同一杯就好了。所以k<=1e6毫无意义。
若选的x杯酒的浓度分别为a,b,c,..,z,则由题意得(a+b+c+...+z)/x=n*x,整理可得(a-n)+(b-n)+(c-n)+...+(z-n)=0。
于是问题就转化成了从所有ai-n中选x个数使得和为0,求x的最小值。
然后由我也不知道怎么证明,可知(a-n),(b-n),(c-n),...,(k-n)可以通过调整顺序使任意前缀和均≥0且≤1000,所以BFS+剪枝即可。相当于在一张1001个结点的稠密无权图上跑最短路,所以时间复杂度为O(10012)。
#include <iostream>
#include <queue>
#define maxn 1005
using namespace std;
int n, m;
int dist[maxn];
bool exist[maxn];
queue<int> que;
int main()
{
ios::sync_with_stdio(false);
cin >> m >> n;
int tmp;
for (int i = ; i <= n; i++)
{
cin >> tmp;
exist[tmp] = true;
} que.push();
while (!que.empty())
{
int x = que.front();
que.pop();
for (int i = ; i <= ; i++)
{
int w = x + i - m;
if (exist[i] && w >= && w <= && !dist[w])
{
que.push(w);
dist[w] = dist[x] + ;
if (w == )
{
cout << dist[];
return ;
}
}
}
}
cout << -;
return ;
}
【Codeforces 788C】The Great Mixing的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 764C】Timofey and a tree
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
随机推荐
- 利用python基于微博数据打造一颗“心”
一年一度的虐狗节将至,朋友圈各种晒,晒自拍,晒娃,晒美食,秀恩爱的.程序员在晒什么,程序员在加班.但是礼物还是少不了的,送什么好?作为程序员,我准备了一份特别的礼物,用以往发的微博数据打造一颗&quo ...
- 深度学习系列 Part(3)
这是<GPU学习深度学习>系列文章的第三篇,主要是接着上一讲提到的如何自己构建深度神经网络框架中的功能模块,进一步详细介绍 Tensorflow 中 Keras 工具包提供的几种深度神经网 ...
- linux GCC 编译多个.c/.h文件
基本认识: #include <xxx>:首先去系统目录中找头文件,如果没有在到当前目录下找.像标准的头文件 stdio.h.stdlib.h等用这个方法. #include " ...
- HDU Today
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- .Net Core在Ubuntu上操作MySql折腾实录
.Net Core 2.0 发布也这么久了,一直想着折腾着玩玩,无奈一直没时间,这几天准备开始好好学习下C#在跨平台方面的应用,记录下来以备自己以后回忆.学习. 本篇博客的主要内容: MySql在Ub ...
- 0_Simple__simpleAssert + 0_Simple__simpleAssert_nvrtc
在核函数中使用强制终止函数 assert().并且在静态代码和运行时编译两种条件下使用. ▶ 源代码:静态使用 #include <windows.h> #include <stdi ...
- JavaScript Function.arguments 属性详解
语法 [functionObject.]arguments arguments属性是正在执行的函数的内置属性,返回该函数的arguments对象.arguments对象包含了调用该函数时所传入的实际参 ...
- linux分析日志的一些常用方法
head -n 2016_05_23_access_log |grep "/859" 显示前10000行中包含 /859 的记录 增加 |wc -l 则改为输出记录数 cat 2 ...
- python jason,pickle
参考官网 https://docs.python.org/3/library/json.html https://docs.python.org/3/library/pickle.html 了解这两个 ...
- 深度学习之seq2seq模型以及Attention机制
RNN,LSTM,seq2seq等模型广泛用于自然语言处理以及回归预测,本期详解seq2seq模型以及attention机制的原理以及在回归预测方向的运用. 1. seq2seq模型介绍 seq2se ...