【PTA 乙级 1038 统计同成绩学生 (20分) C/C++】教程文章相关的互联网学习教程文章

统计学习方法 --- 感知机模型原理及c++实现【代码】【图】

参考博客 Liam Q博客 和李航的《统计学习方法》感知机学习旨在求出将训练数据集进行线性划分的分类超平面,为此,导入了基于误分类的损失函数,然后利用梯度下降法对损失函数进行极小化,从而求出感知机模型。感知机模型是神经网络和支持向量机的基础。下面分别从感知机学习的模型、策略和算法三个方面来介绍。1. 感知机模型 感知机模型如下:f(x)= sign(w*x+b) 其中,x为输入向量,sign为符号函数,括号里面大于等于0,...

Select(快速选择顺序统计量)原理及C++代码实现【代码】

SELECT算法利用快排中的partition思想来进行无序数组的快速选择。寻找第i个顺序统计量可以简单理解为寻找第i小的元素。该算法通过为partition选择一个好的主元,来保证Partition得到一个好的划分。当然partition需要进行一些修改,把划分的主元也作为输入参数。代码如下:(仅供参考) 1void InsertionSort(int * const begin, int * const end) {2int i, j, key;3for (i = 1; i < begin - end; ++i) {4 key = *(begin + i...

[题解]LeetCode 1109. 航班预订统计(C++)【代码】

题目这里有 n 个航班,它们分别从 1 到 n 进行编号。有一份航班预订表 bookings ,表中第 i 条预订记录 \(bookings[i] = [first_i, last_i, seats_i]\) 意味着在从 \(first_i\) 到 \(last_i\) (包含 \(first_i\) 和 \(last_i\))的 每个航班 上预订了 \(seats_i\) 个座位。请你返回一个长度为 n 的数组 answer,其中 answer[i] 是航班 i 上预订的座位总数。示例 1:输入:bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5 输出:[...

C++之路进阶——树链剖分(树的统计)【代码】

2460 树的统计 2008年省队选拔赛浙江 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w。我们将以下面的形式来要求你对这棵树完成一些操作:I. CHANGE u t : 把结点u的权值改为tII. QMAX u v: 询问从点u到点v的路径上的节点的最大权值III. QSUM u v: 询问从点u到点v的路径上的节点...

PTA 乙级 1038 统计同成绩学生 (20分) C/C++【代码】【图】

本以为挺简单的,随便写了写,然后就有了第一个版本注意本题输入输出一定不要用cin,cout,要用scanf,printf(否则更容易超时)C/C++ 1 #include<iostream>2 #include<vector>3 4usingnamespace std;5 6int main() {7int n = 0, k = 0;8int flag = 0;9int search = 0; 10int num = 0; 11 cin >> n; 12 vector<int> grad(n); 13for (int i = 0; i < n; ++i) cin >> grad[i]; 14 cin >> k; 15for (int i = 0; i < k; ++...

面向对象程序设计(基于C++)0401 从文本中统计单词出现的行数【代码】

题目 keywordsCounting.cpp Define a function that, given an istream& and a const vector&, produces a map<string,vector> holding each string (keyword) and the numbers of the line on which the string appears. The line number of the first line is 1. Print in the order of ascending keyword. Run the program on a text file with at least 10000 lines looking for no fewer than 10 keywords. 定义一个函数,给定...

【PAT-B1021】 个位数统计 (15 分)(c++)【代码】

#include<iostream> #include<string> using namespace std;void test01() {//由于int类型,装不下那么多位数,在此采用string类型string num;cin >> num;int arr[10] = { 0 };for (int i = 0; i < num.length(); i++){int nu = 0;nu = (int)num[i] - 48;//cout << nu << endl;arr[nu] = arr[nu] + 1;}//输出arr[]数组for (int i = 0; i < 10; i++){if (arr[i] != 0){cout << i << ":" << arr[i] << endl;}} }int main() {test01()...

C++统计单词频率【代码】

问题描述: //对文中内容单词数量进行统计排序输出,统计时不区分大小写,只统计出现次数大于3的单词,并按降序排列输出, //仅提供cpp内容在答案中。(前10名加分) //例如输入一段英文 //输入:This is a gorup of ……………………. //输出: is 5 of 4 group 4 话不多说:先上代码 #include<iostream> #include<sstream> #include<map> #include<string> #include<algorithm> using namespace std;//通过STL的transform算法配...

<leetcode c++>730. 统计不同回文子序列(分类DP)【代码】

730. 统计不同回文子序列给定一个字符串 S,找出 S 中不同的非空回文子序列个数,并返回该数字与 10^9 + 7 的模。 通过从 S 中删除 0 个或多个字符来获得子序列。 如果一个字符序列与它反转后的字符序列一致,那么它是回文字符序列。 如果对于某个 i,A_i != B_i,那么 A_1, A_2, ... 和 B_1, B_2, ... 这两个字符序列是不同的。 示例 1: 输入: S = bccb 输出:6 解释: 6 个不同的非空回文子字符序列分别为:b, c, bb, cc, bc...

【LeetCode】C++ :简单题 - 字符串 1684. 统计一致字符串的数目【代码】

1684. 统计一致字符串的数目 难度简单5 给你一个由不同字符组成的字符串 allowed 和一个字符串数组 words 。如果一个字符串的每一个字符都在 allowed 中,就称这个字符串是 一致字符串 。 请你返回 words 数组中 一致字符串 的数目。 示例 1: 输入:allowed = "ab", words = ["ad","bd","aaab","baa","badab"] 输出:2 解释:字符串 "aaab" 和 "baa" 都是一致字符串,因为它们只包含字符 'a' 和 'b' 。示例 2: 输入:allowed =...

Leetcode1684. 统计一致字符串的数目[C++题解]:字符串O(n^2)简单题【代码】【图】

文章目录 题目分析题目链接题目分析对于vector中的每一个字符串,遍历之,如果出现不同的字母就放弃,继续遍历下一个,如果该字符串中的每个字母都是allowed中的,计数器加1. ac代码 class Solution { public:int countConsistentStrings(string allowed, vector<string>& words) {int n = words.size();int res=0;for(int i=0;i<n;i++){string t=words[i];// cout<<t<<endl;for(int j=0;j<t.size();j++){if( allowed.find(t[j])==...

C++不调用string实现字符串中子串重复次数统计【代码】

提要 C++标准库中封装了很好用的string类型,可以轻松通过find查找子串。 这里给出一种纯粹使用char*的子串统计实现 实现 嵌套遍历母串和子串进行逐个比对,核心是计数器自增的时机 #include<iostream>int match(const char* main,const char* sub) {int count = 0;for(int i=0;main[i]!='\0';i++){for(int j=0;sub[j]!='\0';j++){if(main[i+j]!=sub[j]){break;}if(sub[j+1]=='\0'){count++;} //core} }return count; }int...

PTA 乙级 1038 统计同成绩学生 (20分) C/C++【代码】【图】

本以为挺简单的,随便写了写,然后就有了第一个版本 注意本题输入输出一定不要用cin,cout,要用scanf,printf(否则更容易超时) C/C++ 1 #include<iostream>2 #include<vector>3 4 using namespace std;5 6 int main() {7 int n = 0, k = 0;8 int flag = 0;9 int search = 0; 10 int num = 0; 11 cin >> n; 12 vector<int> grad(n); 13 for (int i = 0; i < n; ++i) cin >> grad[i]; 14 cin >> ...

c++-字符串中的单词统计与单词大小排序【代码】

1 #include <iostream>2 #include <climits>3 #include <string>4 #include <cstring>5 #include <vector>6 #include <cmath> 7 using namespace std;8 int main() 9 { 10 string line1 = "We were her pride of 10 she named us:";11 string line2 = "Benjamin, Phoenix, the Prodigal";12 string line3 = "and perspicacious pacific Suzanne";13 string sentence = line1 + " " + line2 + " " + line3;...

洛谷P1567统计天数 C++解法【代码】【图】

洛谷P1567统计天数先上我的失败代码: #include<stdio.h> #include <iostream> #include <iomanip> #include<cmath> #include <algorithm> using namespace std;int main() {int n;int temp[100001] = { 0 };cin >> n;for (int i = 0; i < n; i++){cin >> temp[i];}int cnt = 0;int times = 0;int daynum = 0;/*cnt:加到哪一位了times:递增几位了num[]:递增天数记录daynum:num数组的位标思路是利用逐个记录递增的天数再利用sor...