当前位置:网站首页>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
边栏推荐
- Large factory technology implementation | industry solution series tutorials
- Application of Bloom filter in 100 million flow e-commerce system
- 一刷312-简单重复set-剑指 Offer 03. 数组中重复的数字(e)
- 删除字符串中出现次数最少的字符
- 基础贪心总结
- Temporal model: long-term and short-term memory network (LSTM)
- 计算某字符出现次数
- WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile
- WPS品牌再升级专注国内,另两款国产软件低调出国门,却遭禁令
- php类与对象
猜你喜欢
Pgpool II 4.3 Chinese Manual - introductory tutorial
Redis主从复制过程
JVM-第2章-类加载子系统(Class Loader Subsystem)
Multi level cache usage
新动态:SmartMesh和MeshBox的合作新动向
Recommended search common evaluation indicators
Cap theorem
Neodynamic Barcode Professional for WPF V11. 0
One brush 314 sword finger offer 09 Implement queue (E) with two stacks
服务器中毒了怎么办?服务器怎么防止病毒入侵?
随机推荐
Mumu, go all the way
通过 PDO ODBC 将 PHP 连接到 MSSQL
APISIX jwt-auth 插件存在错误响应中泄露信息的风险公告(CVE-2022-29266)
时序模型:长短期记忆网络(LSTM)
服务器中毒了怎么办?服务器怎么防止病毒入侵?
Best practices of Apache APIs IX high availability configuration center based on tidb
Deeply learn the skills of parameter adjustment
One brush 313 sword finger offer 06 Print linked list from end to end (E)
[AI weekly] NVIDIA designs chips with AI; The imperfect transformer needs to overcome the theoretical defect of self attention
Basic concepts of website construction and management
大厂技术实现 | 行业解决方案系列教程
MySQL集群模式與應用場景
PHP function
一刷313-剑指 Offer 06. 从尾到头打印链表(e)
cadence SPB17.4 - Active Class and Subclass
Go language slice, range, set
The length of the last word of the string
Go language, condition, loop, function
utils. Deprecated in35 may be cancelled due to upgrade. What should I do
什么是CNAS认证?CNAS认可的软件测评中心有哪些?