C++中满足线方程的有序点对的数量
在本教程中,我们将编写一个程序来计算满足线方程的阶点对。
应该满足的线方程是y=mx+c。
让我们看看解决问题的步骤。
初始化数组m和c。
编写两个循环以从数组中获取所有对。
检查该对是否满足线方程。
如果该对满足线方程,则增加计数。
示例
让我们看看代码。
#include输出结果using namespace std; bool isSatisfyingLineEquation(int arr[], int i, int j, int m, int c) { if (i == j) { return false; } return arr[j] == m * arr[i] + c; } int getOrderedPointsPairCount(int arr[], int n, int m, int c) { int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (isSatisfyingLineEquation(arr, i, j, m, c)) { count++; } } } return count; } int main() { int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int n = 10; int m = 1, c = 1; cout << getOrderedPointsPairCount(arr, n, m, c) << endl; return 0; }
如果你运行上面的代码,那么你会得到下面的结果。
9
结论
如果您对本教程有任何疑问,请在评论部分提及。
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短