当前位置:网站首页>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
边栏推荐
- 移动app测试如何进行?
- Calculate the number of occurrences of a character
- CVPR 2022 优质论文分享
- 北京某信护网蓝队面试题目
- Neodynamic Barcode Professional for WPF V11. 0
- Deeply learn the skills of parameter adjustment
- 网站建设与管理的基本概念
- Codejock Suite Pro v20.3.0
- 自动化测试框架常见类型▏自动化测试就交给软件测评机构
- Use bitnami PostgreSQL docker image to quickly set up stream replication clusters
猜你喜欢
随机推荐
贫困的无网地区怎么有钱建设网络?
Sorting and replying to questions related to transformer
php类与对象
网站建设与管理的基本概念
Independent operation smart farm Innovation Forum
移动app软件测试工具有哪些?第三方软件测评小编分享
Basic concepts of website construction and management
Explanation of redis database (IV) master-slave replication, sentinel and cluster
s16. One click installation of containerd script based on image warehouse
Cookie&Session
字符串最后一个单词的长度
Connect PHP to MSSQL via PDO ODBC
软件性能测试报告起着什么作用?第三方测试报告如何收费?
Pgpool II 4.3 Chinese Manual - introductory tutorial
Large factory technology implementation | industry solution series tutorials
Go并发和通道
WPS品牌再升级专注国内,另两款国产软件低调出国门,却遭禁令
Upgrade MySQL 5.1 to 5.611
【AI周报】英伟达用AI设计芯片;不完美的Transformer要克服自注意力的理论缺陷
CVPR 2022 优质论文分享