当前位置:网站首页>基础贪心总结
基础贪心总结
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
边栏推荐
- Connect PHP to MSSQL via PDO ODBC
- MySQL InnoDB transaction
- adobe illustrator 菜单中英文对照
- Mysql database explanation (10)
- 通过 PDO ODBC 将 PHP 连接到 MySQL
- Introduction to dynamic programming of leetcode learning plan day3 (198213740)
- php类与对象
- Comparaison du menu de l'illustrateur Adobe en chinois et en anglais
- About UDP receiving ICMP port unreachable
- 机器学习——逻辑回归
猜你喜欢
考试考试自用
TLS / SSL protocol details (30) RSA, DHE, ecdhe and ecdh processes and differences in SSL
setcontext getcontext makecontext swapcontext
TLS / SSL protocol details (28) differences between TLS 1.0, TLS 1.1 and TLS 1.2
Tun equipment principle
让阿里P8都为之着迷的分布式核心原理解析到底讲了啥?看完我惊了
X509 certificate cer format to PEM format
Sword finger offer (1) -- for Huawei
API gateway / API gateway (II) - use of Kong - load balancing
regular expression
随机推荐
Lotus DB design and Implementation - 1 Basic Concepts
我的树莓派 Raspberry Pi Zero 2W 折腾笔记,记录一些遇到的问题和解决办法
MySQL InnoDB transaction
如何设计一个良好的API接口?
PHP PDO ODBC loads files from one folder into the blob column of MySQL database and downloads the blob column to another folder
网站建设与管理的基本概念
After time judgment of date
What are the mobile app software testing tools? Sharing of third-party software evaluation
php类与对象
Code live collection ▏ software test report template Fan Wen is here
Tun equipment principle
setcontext getcontext makecontext swapcontext
Design of digital temperature monitoring and alarm system based on DS18B20 single chip microcomputer [LCD1602 display + Proteus simulation + C program + paper + key setting, etc.]
控制结构(二)
2022年中国数字科技专题分析
Mysql连接查询详解
The El tree implementation only displays a certain level of check boxes and selects radio
Detailed explanation of C language knowledge points -- first understanding of C language [1] - vs2022 debugging skills and code practice [1]
[leetcode daily question] install fence
Mysql database explanation (VII)