当前位置:网站首页>基础贪心总结
基础贪心总结
2022-04-23 15:32:00 【MC快乐的苦小怕】
/* 基础贪心 - - 核心部分 */
/*
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;
部分背包__
策略:以性价比的高低排序,再将物品可以带走的部分带走装进背包
*/
/*
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;
______装载问题
策略:尽可能装重量比较小的。
*/
/*
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 ;
___乘船问题
策略:将目前最重的人和最轻的人搭配,如果不能搭配就让重的人单独做一座船 。
*/
/*
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 ;
}
任务调度问题______
策略:按罚款的金额排序,然后模拟一个日历的标记数组,尽量将时间安排的靠后,给那修需要完成时间比较早的任务留时间。
/*
版权声明
本文为[MC快乐的苦小怕]所创,转载请带上原文链接,感谢
https://xiaoguogsc.blog.csdn.net/article/details/121903425
边栏推荐
- 通过 PDO ODBC 将 PHP 连接到 MySQL
- Application of skiplist in leveldb
- Mysql database explanation (10)
- 网站建设与管理的基本概念
- Squid agent
- Comparaison du menu de l'illustrateur Adobe en chinois et en anglais
- Openfaas practice 4: template operation
- Differential privacy (background)
- 什么是CNAS认证?CNAS认可的软件测评中心有哪些?
- Functions (Part I)
猜你喜欢

KNN, kmeans and GMM

G007-hwy-cc-estor-03 Huawei Dorado V6 storage simulator construction

推荐搜索 常用评价指标

Analysis of common storage types and FTP active and passive modes

让阿里P8都为之着迷的分布式核心原理解析到底讲了啥?看完我惊了

激活函数的优缺点和选择

cadence SPB17.4 - Active Class and Subclass

服务器中毒了怎么办?服务器怎么防止病毒入侵?

Machine learning - logistic regression

自主作业智慧农场创新论坛
随机推荐
Deeply learn the skills of parameter adjustment
Connect PHP to MySQL via PDO ODBC
TLS / SSL protocol details (30) RSA, DHE, ecdhe and ecdh processes and differences in SSL
Llvm - generate local variables
Redis cluster principle
Comparaison du menu de l'illustrateur Adobe en chinois et en anglais
SSH connects to the remote host through the springboard machine
fatal error: torch/extension.h: No such file or directory
Openfaas practice 4: template operation
Crawling fragment of a button style on a website
What are the mobile app software testing tools? Sharing of third-party software evaluation
G007-HWY-CC-ESTOR-03 华为 Dorado V6 存储仿真器搭建
Design of digital temperature monitoring and alarm system based on DS18B20 single chip microcomputer [LCD1602 display + Proteus simulation + C program + paper + key setting, etc.]
通过 PDO ODBC 将 PHP 连接到 MySQL
Mysql database explanation (VII)
Today's sleep quality record 76 points
机器学习——逻辑回归
C language super complete learning route (collection allows you to avoid detours)
Educational codeforces round 127 A-E problem solution
adobe illustrator 菜单中英文对照