当前位置:网站首页>0/1分数规划专题
0/1分数规划专题
2022-06-29 20:03:00 【Snow_raw】
0/1分数规划
- 对于一类:每个元素有两个属性A,B。
- 选择若干元素,使得 ∑ A i ∑ B i \frac{\sum A_i}{\sum B_i} ∑Bi∑Ai取到最值。
- 通常采用二分检验,视情况建模。
- 需要具有单调性。
单词环
选自:Acwing lew2018 的分析

代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
const int N = 1010,M=100100;
int h[N],e[M],ne[M],idx,w[M];
bool st[N];
int cnt[N];
double dist[N];
void add(int a,int b,int c){
e[idx]=b;
w[idx]=c;
ne[idx]=h[a];
h[a]=idx++;
}
bool check(double x){
//平均值
queue<int>q;
memset(st,0,sizeof st);
memset(cnt,0,sizeof(cnt));
for(int i=0;i<676;i++){
q.push(i);
st[i]=true;
}
int count=0;
while(q.size()){
auto t=q.front();
q.pop();
st[t]=false;
for(int i=h[t];i!=-1;i=ne[i]){
int j=e[i];
if(dist[j]<dist[t]+w[i]-x){
//正环
dist[j]=dist[t]+w[i]-x;
cnt[j]=cnt[t]+1;
//玄学判环
if(++count>10000)return true;
if(cnt[j]>=676)return true;
if(!st[j]){
st[j]=true;
q.push(j);
}
}
}
}
return false;
}
signed main(){
while(cin>>n){
if(!n)break;
memset(h,-1,sizeof h);
string s;
for(int i=1;i<=n;i++){
cin>>s;
if(s.size()>=2){
int left=(s[0]-'a')*26+s[1]-'a';
int right=(s[s.size()-2]-'a')*26+s[s.size()-1]-'a';
int len=s.size();
add(left,right,len);
}
}
if(!check(0))cout<<"No solution"<<endl;
else{
double l=0,r=1000;
while(r-l>=1e-4){
double mid=(r+l)/2;
if(check(mid))l=mid;
else r=mid;
}
cout<<l<<endl;
}
}
return 0;
}
边栏推荐
猜你喜欢

【Try to Hack】vulnhub narak

Lock4j -- distributed lock Middleware -- customize the logic of lock acquisition failure

Connaissance générale des paramètres de sécurité du serveur Cloud
![[notes] take notes again -- learn by doing Verilog HDL – 014](/img/92/ba794253f1588ff9ad87d2571a453e.png)
[notes] take notes again -- learn by doing Verilog HDL – 014

Configuration du Flume 4 - source personnalisée + sink

Tiger painter mengxiangshun's digital collection is on sale in limited quantities and comes with Maotai in the year of the tiger

Real time tracking of bug handling progress of the project through metersphere and dataease
![[boutique] detailed explanation of Pinia](/img/94/d332e32dba54be3c2d3f6ff08a85fa.png)
[boutique] detailed explanation of Pinia

Finally, Amazon~

Koa source code analysis
随机推荐
【译】十二因子应用(四)
[sword finger offer] 51 Reverse pair in array
Flume configuration 2 - ganglia for monitoring
WPS and Excelle
【U盘检测】为了转移压箱底的资料,买了个2T U盘检测仅仅只有47G~
How to use filters in jfinal to monitor Druid for SQL execution?
How to use the configuration in thinkphp5
Summary of swift optional values
Measures to support the development of advanced manufacturing industry in Futian District of Shenzhen in 2022
关于印发宝安区重点产业项目和总部项目遴选及用地保障实施细则(2022修订版)的通知
How to solve the problem of insufficient memory space in Apple iPhone upgrade system?
Golang基础学习
Dynamics crm: among locally deployed servers, sandbox, unzip, VSS, asynchronous and monitor services
One hour to build a sample scenario sound network to release lingfalcon Internet of things cloud platform
【编译原理】类型检查
Community interview -- jumpserver open source fortress in the eyes of an it newcomer
Zotero journal Automatic Matching Update Influencing Factors
lock4j--分布式锁中间件--自定义获取锁失败的逻辑
7. cancellation and closing
Spark存储体系底层架构剖析-Spark商业环境实战