灰度直方图 C++解法

CSP 灰度直方图C++11解法

解题思路

思路比较简单,直接遍历像素值即可。时间复杂度为O(mn)

代码

#include<iostream>
#include<vector>
using namespace std;

class Solution {

	public:
		vector<int> zhiFangTu1(int n,int m,int L,vector<vector<int>> graph) {

			vector<int> res(L,0);
			for(int i=0; i<n; i++) {
				for(int j=0; j<m; j++) {
					res[graph[i][j]]++;
				}

			}

			return res;
		}



};

int main() {
	int n,m,L;

	cin>>n>>m>>L;
	vector<vector<int>> graph(n);
	for (int i=0; i<n; i++) {
		for(int j=0; j<m; j++) {

			int temp;
			cin>>temp;
			graph[i].push_back(temp);
		}
	}

//	cout<<"开始输出:"<<endl;
//	cout<<n<<" "<<m<<" "<<L<<endl;
//
//	for (auto &single:graph){
//		for (auto &num:single){
//			cout<<num<<" ";
//		}
//		cout<<endl;
//	}

	Solution solution;

	vector<int> res=solution.zhiFangTu1(n,m,L,graph);
//	cout<<"结果为"<<endl;
	for(auto &num:res) {
		cout<<num<<" ";
	}





}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值