当前位置:网站首页>Openjudge noi 2.1 1752: chicken and rabbit in the same cage
Openjudge noi 2.1 1752: chicken and rabbit in the same cage
2022-07-07 08:10:00 【Jun Yi_ noip】
【 Topic link 】
OpenJudge NOI 2.1 1752: Chicken and rabbit in the same cage
【 Topic test site 】
1. enumeration
【 Their thinking 】
solution 1: enumeration
With chicken x only , The rabbit y only , It is known that there is a One foot , So there are
2 x + 4 y = a 2x+4y=a 2x+4y=a
Chicken has at least 0 only , When all feet are chicken feet , Most chickens , Yes a 2 \frac{a}{2} 2a only , therefore 0 ≤ x ≤ a 2 0\le x \le \frac{a}{2} 0≤x≤2a
Rabbits have at least 0 only , At most ⌊ a 4 ⌋ \lfloor \frac{a}{4} \rfloor ⌊4a⌋ only , therefore 0 ≤ y ≤ ⌊ a 4 ⌋ 0\le y \le \lfloor \frac{a}{4} \rfloor 0≤y≤⌊4a⌋
Summed up in :
- enumerable object :x, y
- Enumeration range : 0 ≤ x ≤ a 2 0\le x \le \frac{a}{2} 0≤x≤2a, 0 ≤ y ≤ ⌊ a 4 ⌋ 0\le y \le \lfloor \frac{a}{4} \rfloor 0≤y≤⌊4a⌋
- Enumeration condition : 2 x + 4 y = a 2x+4y=a 2x+4y=a
Select all that meet the conditions x And y in ,x+y Maximum and minimum values of .
solution 2: Looking for a regular
If the number of input feet is odd , Then there is no answer that meets the requirements .
When there are as many chickens as possible , Animals should be the most . When there are as many rabbits as possible , Animals should be the least .
Chicken up to a 2 \frac{a}{2} 2a, Then the animals are at most a 2 \frac{a}{2} 2a
Rabbits are at most ⌊ a 4 ⌋ \lfloor \frac{a}{4} \rfloor ⌊4a⌋, be left over a % 4 a\%4 a%4 Every foot is a chicken , Yes a % 4 2 \frac{a\%4}{2} 2a%4 only , At this time, the animals are at least , Yes ⌊ a 4 ⌋ + a % 4 2 \lfloor \frac{a}{4} \rfloor+\frac{a\%4}{2} ⌊4a⌋+2a%4 only .
【 Solution code 】
solution 1: enumeration
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
int main()
{
int a, mx = 0, mn = INF;
cin >> a;
for(int x = 0; x <= a/2; ++x)
for(int y = 0; y <= a/4; ++y)
{
if(2*x+4*y == a)
{
// Update the maximum and minimum values
mx = max(mx, x+y);
mn = min(mn, x+y);
}
}
if(mx == 0 && mn == INF)// If not found
cout << "0 0";
else
cout << mn << ' ' << mx;
return 0;
}
solution 2: Looking for a regular
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a;
cin >> a;
if(a % 2 == 1)
cout << "0 0";
else
cout << a/4+a%4/2 << ' ' << a/2;
return 0;
}
边栏推荐
猜你喜欢
海信电视开启开发者模式
Linux server development, redis source code storage principle and data model
复杂网络建模(一)
CDC (change data capture technology), a powerful tool for real-time database synchronization
json 数据展平pd.json_normalize
互动送书-《Oracle DBA工作笔记》签名版
Es FAQ summary
Codeforce c.strange test and acwing
追风赶月莫停留,平芜尽处是春山
【数字IC验证快速入门】11、Verilog TestBench(VTB)入门
随机推荐
jeeSite 表单页面的Excel 导入功能
Few shot Learning & meta learning: small sample learning principle and Siamese network structure (I)
【数字IC验证快速入门】14、SystemVerilog学习之基本语法1(数组、队列、结构体、枚举、字符串...内含实践练习)
复杂网络建模(一)
Complex network modeling (III)
【數字IC驗證快速入門】15、SystemVerilog學習之基本語法2(操作符、類型轉換、循環、Task/Function...內含實踐練習)
Zsh shell adds automatic completion and syntax highlighting
Empire CMS collection Empire template program general
json 数据展平pd.json_normalize
Use of JMeter
[VHDL parallel statement execution]
[untitled]
互动送书-《Oracle DBA工作笔记》签名版
The legend about reading the configuration file under SRC
Blob 對象介紹
青龙面板-今日头条
Complete linear regression manually based on pytoch framework
padavan手动安装php
Summary of redis functions
Recursive method constructs binary tree from middle order and post order traversal sequence