Codeforces 231A.Team(brute force, greedy)

上一篇博客:第十二届蓝桥杯省赛第一场C/C++ B组真题及部分题解

 写在前面:大家好!我是晴空๓。如果博客中有不足或者的错误的地方欢迎在评论区或者私信我指正,感谢大家的不吝赐教。我的唯一博客更新地址是:https://ac-fun.blog.csdn.net/。非常感谢大家的支持。一起加油,冲鸭!
用知识改变命运,用知识成就未来!加油 (ง •̀o•́)ง (ง •̀o•́)ง

原题链接:Codeforces 231A.Team

The title information

Problem description

 One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won’t write the problem’s solution.

 This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.

Input

 The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem’s solution, otherwise he isn’t sure. The second number shows Vasya’s view on the solution, the third number shows Tonya’s view. The numbers on the lines are separated by spaces.

Output

 Print a single integer — the number of problems the friends will implement on the contest.

Examples

input one

3
1 1 0
1 1 1
1 0 0

output one

2

input two

2
1 0 0
0 1 1

output two

1

Note

 In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn’t enough, so the friends won’t take it.

 In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.

Answer

The title mean

 题目大概的意思是三个同学组队参加 ACM,只有当两个或者两个以上同学确定他们的题目可以 Accepted 的时候他们才会提交题目。问最后他们一共会提交几次题目。输入一个字母 n 表示比赛一共有几道题目,接下来的 n 行输入 n 条数据,没条数据一次表示三位同学是否确定他们的题目可以 Accepted,如果为 1 表示确定,0 表示不确定。最后输出正常比赛他们确定提交几道题目。

Ideas

 因为题目的数据范围比较小,所以可以直接边输入边统计,最后输出结果即可。

AC code

#include<iostream>
#include<cstdio>

using namespace std;
int n, ans;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b, c, cnt = 0;
		cin >> a >> b >> c;
		if (a) cnt++;
		if (b) cnt++;
		if (c) cnt++;
		if (cnt >= 2) ans++;
	}
	cout << ans;
	return 0;
}

未完待续,持续更新中……
嘿嘿

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
遗传算法选址问题是一种使用遗传算法来求解的问题。在Python中,可以使用geatpy库来进行遗传算法的实现。首先,我们需要自定义问题类来描述选址问题的特征和限制条件。然后,编写执行脚本调用geatpy进化算法模板对问题进行求解。 在geatpy库中,可以使用交叉操作来实现个体的交换和组合。交叉操作是遗传算法中的一个重要步骤,通过将两个父代个体的染色体进行配对交换,产生新的子代个体。 具体的步骤如下: 1. 首先,定义选址问题的目标函数和约束条件。目标函数可以是优化问题中需要最小化或最大化的指标,而约束条件则是限制解的可行性的条件。 2. 接下来,根据选址问题的特征和限制条件,创建一个自定义的问题类,继承自geatpy库中的Problem基类。 3. 在问题类中,需要定义目标函数和约束条件的计算方法,以及决策变量的取值范围等信息。 4. 然后,编写执行脚本,调用geatpy进化算法模板对问题进行求解。在执行脚本中,需要创建问题实例,并设置算法参数,例如种群大小、迭代次数等。 5. 最后,运行执行脚本,观察算法的收敛情况和最优解的结果。根据实际情况,可以调整算法参数或修改问题类以改进算法的性能。 总结起来,遗传算法选址问题的求解步骤包括目标函数和约束条件的定义、问题类的创建和算法模板的调用。通过这些步骤,可以使用geatpy库来实现遗传算法解决选址问题的求解过程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晴空๓

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值