当前位置:网站首页>Topic 1125: - delegate * C language training
Topic 1125: - delegate * C language training
2022-07-29 14:28:00 【Lele if you don't understand】
题目描述
某侦察队接到一项紧急任务,要求在A、B、C、D、E、F六个队员中尽可能多地挑若干人,但有以下限制条件:
1)A和B两人中至少去一人;
2)A和D不能一起去;
3)A、E和F三人中要派两人去;
4)B和C都去或都不去;
5)C和D两人中去一个;
6)若D不去,则E也不去.
问应当让哪几个人去?
输入格式
无
输出格式
person to send
若有多个,In ascending alphabetical order,用逗号分开(with trailing comma)
样例输入
复制
无
样例输出
复制
A,B,C,F,
This is my first time doing this shit,,No clue at first,Still want to draw lessons from bosses
1.思路,创建变量,初始值为0 ,,逐步增加,1代表去,0 代表不去
然后用for循环遍历,,The previous code that can be passed
#include<stdio.h>
void print(int a, int b, int c, int d, int e, int f)
{
if (a == 1)
{
printf("A,");
}
if (b == 1)
{
printf("B,");
}
if (c == 1)
{
printf("C,");
}
if (d == 1)
{
printf("D,");
}
if (e == 1)
{
printf("E,");
}
if (f == 1)
{
printf("F,");
}
}
int judg(int a, int b, int c, int d, int e, int f)
//Here I found the opposite of each request,,,ideas than in aifThere is a lot of writing in it to be clear
{
if (a == 0 && b == 0)
{
return 0;
}
if (a == 1 && d == 1)
{
return 0;
}
if ((b == 0 && c == 1) || (b == 1 && c == 0))
{
return 0;
}
if ((c == 0 && d == 0) || (c == 1 && d == 1))
{
return 0;
}
if (d == 0 && e == 1)
{
return 0;
}
if (a == 0 && e == 0 && f == 0)//去0个
{
return 0;
}
if ((a == 1 && e == 0 && f == 0) || (a == 0 && e == 1 && f == 0) || (a == 0 && e == 0 && f == 1))
{
return 0;
}
if (a == 1 && e == 1 && f == 1)
{
return 0;
}
return 1;
}
int main()
{
int a = 0; int b = 0; int c = 0;
int d = 0; int e = 0; int f = 0;
for (a = 0; a < 2; a++)
{
for (b = 0; b < 2; b++)
{
for (c = 0; c < 2; c++)
{
for (d = 0; d < 2; d++)
{
for (e = 0; e < 2; e++)
{
for (f = 0; f < 2; f++)
{
int k = judg(a, b, c, d, e, f);//判断是否满足条件
if (k == 1)
{
print(a, b, c, d, e, f);//输出函数
return 0;
}
}
}
}
}
}
}
return 0;
}Then let's improve,The problem with this code is
1. Pass if you meet the conditions,无法找到最优解
2.Difficulty in passing ginseng,,To several parameters,,懒!
3.There are also different methods in the judgment process
改进:对于创建6个变量,Why not create an array,Then record each possible value,Finally find meet the conditions of the optimal solution!!!@#¥%……
#include<stdio.h>
void change(int arr[10], int a, int b, int c, int d, int e, int f)
{
if (a == 1)
{
arr['a' - 'a' + 1]++;
}
if (b == 1)
{
arr['b' - 'a' + 1]++;
}
if (c == 1)
{
arr['c' - 'a' + 1]++;
}
if (d == 1)
{
arr['d' - 'a' + 1]++;
}
if (e == 1)
{
arr['e' - 'a' + 1]++;
}
if (f == 1)
{
arr['f' - 'a' + 1]++;
}
}
void print(int arr[10])
{
int i = 0;
for (; i<7; i++)
{
if (arr[i] == 1)
{
printf("%c,", i + 'A' - 1);
}
}
}
int judg(int a, int b, int c, int d, int e, int f)
{
if (a == 0 && b == 0)
{
return 0;
}
if (a == 1 && d == 1)
{
return 0;
}
if ((b == 0 && c == 1) || (b == 1 && c == 0))
{
return 0;
}
if ((c == 0 && d == 0) || (c == 1 && d == 1))
{
return 0;
}
if (d == 0 && e == 1)
{
return 0;
}
if (a == 0 && e == 0 && f == 0)//去0个
{
return 0;
}
if ((a == 1 && e == 0 && f == 0) || (a == 0 && e == 1 && f == 0) || (a == 0 && e == 0 && f == 1))
{
return 0;
}
if (a == 1 && e == 1 && f == 1)
{
return 0;
}
int num = 0;
if (a == 1) { num++; }
if (b== 1) { num++; }
if (c == 1) { num++; }
if (d== 1) { num++; }
if (e == 1) { num++; }
if (f== 1) { num++; }
return num;
}
int main()
{
//创建一个只有7位的数组,用123来代替abc,
//
// Then in order to record,I thought of using a two-dimensional array,或者结构体,
//有2的6method in power,Just two of the six to the power line
int i = 0;
int a = 0; int b = 0; int c = 0;
int d = 0; int e = 0; int f = 0;
int arr[100][10] = { 0 };
for (a = 0; a < 2; a++)
{
for (b = 0; b < 2; b++)
{
for (c = 0; c < 2; c++)
{
for (d = 0; d < 2; d++)
{
for (e = 0; e < 2; e++)
{
for (f = 0; f < 2; f++)
{
int k = judg(a, b, c, d, e, f);
if (k!=0)
{
arr[i][0] = k;
change(arr[i], a, b, c, d, e, f);
i++;
}
}
}
}
}
}
}
//
int max = arr[0][0];
int max_id = 0;
int j = 0;
for (j = 0; j < i; j++)
{
if (arr[j][0] > max)
{
max = arr[j][0];
max_id = j;
}
}
print(arr[max_id]);
return 0;
}尽力了,In this way, it is possible to find the optimal solution
边栏推荐
- leetcode linked list topic
- 480-82(59、151)
- 浅谈如何在渗透测试中快速搞定webshell
- Redis-NoSql
- The new technical director, who is in the form of a isXxx Boolean type definition, tomorrow need not come!
- About inner classes
- 【FreeSwitch开发实践】自定义模块创建与使用
- 国产手机将用户变成它们的广告肉鸡,难怪消费者都买iPhone了
- 城市污水处理过程模型预测控制研究综述
- 工作效率-十五分钟让你快速学习Markdown语法到精通排版实践备忘
猜你喜欢

Offensive EA&UML day arch - activity diagram: : Variable Actions (continue)

2022开放原子全球开源峰会数据库分论坛圆满召开

日志打印不规范,被CTO骂了一顿~

【FreeSwitch开发实践】自定义模块创建与使用

2022年七夕情人节有什么值得推荐的礼物选择?实用且高级礼物推荐

何为擦除机制,泛型的上界?

【论文阅读】异常检测的视频通过Self-Supervised和多任务学习

项目经理:不错啊!SSO单点登录代码写出来了,把时序图也画一下?

暴力递归到动态规划 02 (绝顶聪明的人的纸牌游戏)

工作效率-十五分钟让你快速学习Markdown语法到精通排版实践备忘
随机推荐
在金融服务行业数字化转型中,低代码值得被关注
蚂蚁三面滑铁卢!遭分布式截胡,靠这些笔记潜修30天,挺进京东
The Location object of BOM series
Violence recursion to dynamic programming 02 (very clever game of CARDS)
The key to cracking AI full-process development problems
164. 可达性统计
教育部等五部门联合推荐优质课外资源,腾讯产品青少年模式首发
小程序开发模板设计怎么做?
Pinia状态持久化
这么多年了,还搞不懂正则语法?
何为擦除机制,泛型的上界?
打卡广汽本田喜悦安全驾驶中心,体验最刁钻的场地训练
3555. 二叉树
Alibaba CTO Cheng Li: open source is the source of basic software!
全开放式耳机怎么样?不塞耳朵的蓝牙耳机推荐
AI全流程开发难题破解之钥
Sqoop导入导出时数据内存溢出
性能优化竟白屏,难道真是我的锅?
Programmers are a group with a high incidence of occupational diseases. Don’t be naive to think that it’s just as simple as being bald.
根据msql表的结构自动生成gorm的struct