本文主要是介绍木板容量问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、水桶问题
#include <iostream>
#include <vector>using namespace std;int simple_counter(std::vector<int>* s_sample)
{int max_s=0;int temp_s=0;int compacity=0;for(int i=0;i<s_sample->size()-1;i++){max_s=max(max_s,(*s_sample)[i]);temp_s = min(max_s,(*s_sample)[i+1]);compacity +=temp_s;}return compacity;
}std::vector<int> counter(std::vector<std::vector<int>> *sample)
{std::vector<int> results;int temp_result;for(int i=0;i<sample->size();i++){temp_result = simple_counter(&((*sample)[i]));results.push_back(temp_result);cout<<"sample "<<i<<" result :"<<temp_result<<endl;}return results;
}int main()
{int n_sample,m_column;std::vector<std::vector<int>>sample;cout<<"please input sample amount"<<endl;cin>>n_sample;//载入数据sample.resize(n_sample);for(int i=0;i<n_sample;i++){cout<<"please input column amount:"<<endl;cin>>m_column;cout<<"please input wood amount"<<endl;for(int j=0;j<m_column;j++){int temp;cin>>temp;sample[i].push_back(temp);}}//计算并打印counter(&sample);return 0;
}
2、非齐次线性方程组问题
#include <iostream>
#include <vector>
using namespace std;void solve_mess(double a[][6],int n)
{for(int i=0;i<n;i++){double fenmu=a[i][0]*a[i][4]-a[i][1]*a[i][3];if(fenmu!=0){double price1 = (a[i][2]*a[i][4]-a[i][1]*a[i][5])/fenmu;double price2 = (a[i][0]*a[i][5]-a[i][2]*a[i][3])/fenmu;//判断是否是整数和正数if(price1-(int)price1 == 0 && price2 - (int)price2 ==0&&price1>0&&price2>0)cout<<price1 <<" "<<price2 <<endl;elsecout<<"unknow "<<endl;}else{cout<<"unknow "<<endl;}}
}int main()
{int n ;cout<<"please input sample amount:"<<endl;cin>>n;double a[n][6];for(int i=0;i<n;i++){for(int j=0;j<6;j++){double temp_i;cin>>temp_i;a[i][j]=temp_i;}}solve_mess(a,n);}
3、
这篇关于木板容量问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!