[分块][数学][瞎搞]Codeforces Round #424 .C Bamboo Partition
来源:互联网 发布:西安软件新城软件公寓 编辑:程序博客网 时间:2024/05/20 19:46
刚开始的做法是对的…然而越做头越昏,竟然用错误的例子把自己叉掉…
还好最后半个小时清醒了
先列出式子
要求最大的d满足
其中ai要先减一再取模是为了防止ai是d的倍数的情况,
再推一推
大概就是这样
然后发现,
那么所有
然后从大到小枚举每一种取值,显然答案在是第一种满足条件的取值。
然后把这个取值转化成最大的d就可以了,具体看代码
这样复杂度是跑得过就行
#include <cstdio>#include <iostream>#include <algorithm>#include <vector>#include <map>#include <set>#include <cmath>#define fi first#define se second#define pb push_backusing namespace std;typedef long long ll;typedef pair<int,int> par;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline void rea(int &x){ char c=nc(); x=0; int f=1; for(;c>'9'||c<'0';c=nc())if(c=='-') f=-1; for(;c>='0'&&c<='9';x=x*10+c-'0',c=nc()); x*=f;}inline void rea(ll &x){ char c=nc(); x=0; int f=1; for(;c>'9'||c<'0';c=nc())if(c=='-') f=-1; for(;c>='0'&&c<='9';x=x*10+c-'0',c=nc()); x*=f;}const int N=110;int n,a[N];vector<int> v;ll goal,k;int main(){ rea(n); rea(k); for(int i=1;i<=n;i++) rea(a[i]),goal+=a[i],a[i]--; goal+=k; for(int i=1;i<=n;i++) for(int j=1,d;j<=a[i];j=d+1) d=a[i]/(a[i]/j),v.pb(j); for(int i=1;i<=n;i++) v.pb(a[i]+1); sort(v.begin(),v.end()); //for(int i=0;i<v.size();i++) printf("%d ",v[i]); putchar('\n'); v.resize(unique(v.begin(),v.end())-v.begin()); //for(int i=0;i<v.size();i++) printf("%d ",v[i]); putchar('\n'); int td,last=1<<30; for(int s=v.size()-1;~s;s--){ int d=v[s]; ll cur=0; for(int i=1;i<=n;i++){ cur+=d*(a[i]/d); } if(1LL*n*d+cur<=goal){ td=d; break; } last=d; } ll cur=0; for(int i=1;i<=n;i++) cur+=(a[i]/td); printf("%lld\n",goal/(n+cur)); return 0;}
阅读全文
0 0
- [分块][数学][瞎搞]Codeforces Round #424 .C Bamboo Partition
- Codeforces 424 div1 C. Bamboo Partition 830C 分块优化
- [除法分块] Codeforces 830C Bamboo Partition
- Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) C. Bamboo Partition(数学)
- [杂题] Codeforces 830C Round #424 Div1 C. Bamboo Partition
- codeforces 830C Bamboo Partition
- CodeForces 830C Bamboo Partition
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) F. Bamboo Partition
- CF830C:Bamboo Partition(数学)
- 【数学分析+除法分块】Codeforces830C[Bamboo Partition]题解
- 【瞎搞】 Codeforces Round 276 DIV 2 C.Bits
- Codeforces Round #443 (Div. 1) C. Tournament(瞎搞???)
- Codeforces Round #368-C - Pythagorean Triples-数学
- Educational Codeforces Round 20 C 数学
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] C 数学
- Codeforces Round #424 E. Cards Sorting 线段树/数据结构瞎搞/模拟
- Codeforces 527 C Glass Carving----瞎搞
- 【瞎搞】 Codeforces Round #215 (Div. 1) A Sereja and Algorithm
- Ubuntu总是弹出提示磁盘空间不足
- Java Nio 的Buffer和优缺点
- JDE 查看log
- sun
- jsp通过从数据库读取的字节流(byte[])制作图片
- [分块][数学][瞎搞]Codeforces Round #424 .C Bamboo Partition
- JavaScript笔记(浏览器上--操作DOM)
- redis面试总结
- Spark性能优化指南——基础篇
- java攻城狮之路-面向对象(2)
- JS原生实现多个小球跟着鼠标移动
- jq放大镜
- Linux基础命令总结(CentOS6.9, CentOS7.3)
- MVC、MVP、MVVM之间的关系