当前位置:网站首页>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)
- Node. JS ODBC connection PostgreSQL
- PHP classes and objects
- pywintypes. com_ Error: (- 2147221020, 'invalid syntax', none, none)
- C language --- advanced pointer
- c语言---指针进阶
- 提取不重复的整数
- PHP PDO ODBC loads files from one folder into the blob column of MySQL database and downloads the blob column to another folder
- 网站建设与管理的基本概念
- Timing model: gated cyclic unit network (Gru)
猜你喜欢
随机推荐
PHP PDO ODBC将一个文件夹的文件装载到MySQL数据库BLOB列,并将BLOB列下载到另一个文件夹
PHP PDO ODBC loads files from one folder into the blob column of MySQL database and downloads the blob column to another folder
pywintypes. com_ Error: (- 2147221020, 'invalid syntax', none, none)
String sorting
How do you think the fund is REITs? Is it safe to buy the fund through the bank
Connect PHP to MSSQL via PDO ODBC
s16. One click installation of containerd script based on image warehouse
现在做自媒体能赚钱吗?看完这篇文章你就明白了
Connect PHP to MySQL via PDO ODBC
Open source project recommendation: 3D point cloud processing software paraview, based on QT and VTK
Neodynamic Barcode Professional for WPF V11. 0
Connectez PHP à MySQL via aodbc
Rsync + inotify remote synchronization
Explanation 2 of redis database (redis high availability, persistence and performance management)
什么是CNAS认证?CNAS认可的软件测评中心有哪些?
MySQL optimistic lock to solve concurrency conflict
PHP classes and objects
cadence SPB17.4 - Active Class and Subclass
CVPR 2022 优质论文分享
pgpool-II 4.3 中文手册 - 入门教程









