当前位置:网站首页>Basic greedy summary
Basic greedy summary
2022-04-23 15:44:00 【MC happy bitter little fear】
/* Basic greed - - The core part of the */
/*
bool cmp ( const Wvs &x, const Wvs &y )
{
return x.v>y.v ;
}
for( int i = 1 ;i <= n; i++ )
{
cin >> wvs[i].w >> wvs[i].v ;
wvs[i].v /= wvs[i].w;
}
sort ( wvs + 1 ,wvs + n + 1 ,cmp ) ;
for( int i = 1 ;i <= n; i++ )
{
int x = min ( C, wvs[i].w);
ans += x * wvs[i].v;
C-=x;
if ( C<=0 ) break ;
}
cout << ans;
Some backpacks __
Strategy : Sort by cost performance , Then take away the parts that can be taken away and put them into the backpack
*/
/*
for ( int i = 1; i <= n; i++ )cin >> v[i] ;
sort ( v + 1, v + n + 1 ) ;
for ( int i = 1; i <= n; i++ )
{
if( c >= v[i] ) k++, c-=v[i];
else break;
}
cout << k;
______ Loading problem
Strategy : Try to pack the smaller weight .
*/
/*
int n, C; cin >> n >> C ;
for ( int i = 1; i <= n; i++ ) cin >> v[i] ;
sort ( v + 1, v + n + 1 ) ;
int i = 1, j = n, ans = 0 ;
while ( i <= j )
{
ans ++;
if( v[i] + v[j]<=C ) i++, j-- ;
else j-- ;
}
cout << ans ;
___ The question of taking a boat
Strategy : Match the heaviest person with the lightest person , If you can't match, let the heavy man make a boat alone .
*/
/*
bool used [N] ;
bool cmp ( const Rlg &r, const Rlg &l )
{
return r.money > l.money ;
}
sort ( rlg + 1, rlg + n + 1, cmp ) ;
for ( int i = 1; i <= n; i++ )
{
bool oks=true;
for ( int r = rlg[i].t; r >= 1; r-- )
{
if ( !used[r] ){ used[r] = true; oks = false; break; }
}
if ( oks ) ans += rlg[i].money ;
}
Task scheduling problem ______
Strategy : Sort by amount of penalty , Then simulate a calendar tag array , Try to schedule back , Leave time for tasks that need to be completed earlier .
/*
版权声明
本文为[MC happy bitter little fear]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231531525348.html
边栏推荐
- 一刷314-剑指 Offer 09. 用两个栈实现队列(e)
- Neodynamic Barcode Professional for WPF V11.0
- How do you think the fund is REITs? Is it safe to buy the fund through the bank
- Go language, condition, loop, function
- 负载均衡器
- Mumu, go all the way
- 基础贪心总结
- Redis master-slave replication process
- 移动app软件测试工具有哪些?第三方软件测评小编分享
- Go language, array, pointer, structure
猜你喜欢

【开源工具分享】单片机调试助手(示波/改值/日志) - LinkScope

建设星际计算网络的愿景

时序模型:门控循环单元网络(GRU)

使用 Bitnami PostgreSQL Docker 镜像快速设置流复制集群

KNN, kmeans and GMM

C language --- string + memory function

Pgpool II 4.3 Chinese Manual - introductory tutorial

Today's sleep quality record 76 points

网站压测工具Apache-ab,webbench,Apache-Jemeter

Advantages, disadvantages and selection of activation function
随机推荐
Upgrade MySQL 5.1 to 5.68
Connect PHP to MySQL via PDO ODBC
s16.基于镜像仓库一键安装containerd脚本
移动金融(自用)
Configuration of multi spanning tree MSTP
布隆过滤器在亿级流量电商系统的应用
IronPDF for .NET 2022.4.5455
移动app软件测试工具有哪些?第三方软件测评小编分享
Code live collection ▏ software test report template Fan Wen is here
Why is IP direct connection prohibited in large-scale Internet
Temporal model: long-term and short-term memory network (LSTM)
导入地址表分析(根据库文件名求出:导入函数数量、函数序号、函数名称)
String sorting
Open source project recommendation: 3D point cloud processing software paraview, based on QT and VTK
Cookie&Session
Multitimer V2 reconstruction version | an infinitely scalable software timer
建设星际计算网络的愿景
fatal error: torch/extension. h: No such file or directory
为啥禁用外键约束
多生成树MSTP的配置