我真不想写背景
来源:互联网 发布:网络连接发生意外错误 编辑:程序博客网 时间:2024/03/29 23:01
我真不想写背景
题目描述
某巨魔突然对等式很感兴趣,他正在研究
他要求你编写一个程序,给定
输入格式
输入的第一行包含
输入的第二行包含
输出格式
输出一个整数,表示有多少
样例输入
2 5 10
3 5
样例输出
5
样例解释
对于
对于
对于
对于
对于
对于
数据范围
Solution
因为
对于模
则对于每一个
那么,如何求出
现已知
设
则
这就是一个最短路模型,每次用
Code
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <algorithm>#include <cmath>#define LL long long#define Max(x,y) ((x)>(y)?(x):(y))using namespace std;LL n,bmi,bma,ans;LL a[20],dis[400010];bool in_stack[400010];queue<LL>q;void spfa(){ memset(dis,-1,sizeof dis); dis[0]=0;q.push(0);in_stack[0]=true; while(!q.empty()){ LL now=q.front(); q.pop();in_stack[now]=false; for(LL i=2;i<=n;i++){ LL tmp=now+a[i],qq=0; while(tmp>a[1]){ tmp-=a[1]; qq++; } if(dis[tmp]==-1||dis[tmp]>dis[now]+qq){ dis[tmp]=dis[now]+qq; if(!in_stack[tmp]){ in_stack[tmp]=true; q.push(tmp); } } } }}int main(){ freopen("wth.in","r",stdin); freopen("wth.out","w",stdout); scanf("%lld%lld%lld",&n,&bmi,&bma); for(LL i=1;i<=n;i++)scanf("%lld",&a[i]); sort(a+1,a+n+1); spfa(); for(LL i=0;i<a[1];i++)if(dis[i]!=-1){ LL tmp=i+dis[i]*a[1]; if(tmp>bma)continue; ans+=(bma-tmp)/a[1]-Max((LL)(ceil(((double)bmi-tmp)/a[1])),0)+1; } printf("%lld\n",ans); return 0;}
0 0
- 我真不想写背景
- 我真的不想写背景
- 我不想写背景
- 我真的不想给你开门
- 我已经不想写算法了
- 你真的不想理我了吗?
- 对于这个题目我真的不想再多说什么了
- 我----不想
- 我不想
- 我不想
- 【生活】我不想我不想不想上班
- 2011.11.26-12.10 我不想写总结,我想说说她。
- 真不想这样。。。
- 真的不想监考
- 真的不想行尸走肉
- 真的不想监考
- 我不想说太多,但是我真的可以用气急败坏形容
- 我真的要写博客了~~
- Poj:2503 Babelfish
- Linux基础知识[2]【延迟及定时机制】
- 获取手机串号 版本 品牌
- Webpack案例学习
- OMA DRM原理的研究及实现
- 我真不想写背景
- WPF实现物理效果 拉一个小球
- 访问手机短消息对话的常用URI及部分URI返回数据汇总
- iOS PureLayout的基本使用(二)
- 设计模式 - 观察者模式
- 通过HttpServletRequest获取上一个页面
- int 和Integer 有什么区别?
- Android 自定义控件学习笔记
- C/C++中static关键字作用总结