大疆后台开发A卷
- 咖啡的香气
//大疆软件开发A卷
//咖啡的香气,12分
#include <iostream>
#include <vector>
using namespace std;
int fun(int N, int A, int X, vector<int> input)
{
int total_pre = 60 * A * X + (8 - A) * 60;
int total_pos = 0;
for (int i = 0; i < N; ++i)
{
total_pos += input[i];
}
if (total_pos > total_pre)
return 0;
int total_temp = total_pos;
int X_temp = X;
int time_temp = 0;
while (total_temp > 0)
{
int total_time_temp = total_temp;
if (X_temp > 0)
{
total_temp = total_temp - 60 * A;
--X_temp;
}
else
total_temp = total_temp - 60 * A;
if (total_temp >= 0)
time_temp += 60;
else
{
if (X_temp > -1)
{
if (1 == total_time_temp % 3)
time_temp += (total_time_temp + 3) / 3;
else if(1 == total_time_temp % 3)
time_temp += total_time_temp / 3;
}
else
time_temp += total_time_temp;
}
}
return time_temp;
}
int main()
{
int N;
int A;
int X;
while(cin>>N>>A>>X){
vector<int> input;
int temp;
for(int i = 0;i<N;i++){
cin>>temp;
input.push_back(temp);
}
int count = fun(N,A,X,input);
cout<<count<<endl;
}
system("pause");
return 0;
}
- 应该吃哪个
#include <iostream>
#include <vector>
using namespace std;
//w:价格数组w[0]=0
//v:满意度数组v[0]=0
//m:总钱数
//n:零食种类
//需要把零食按数量拆开存放(比如数量为2,在w,v,n,里面都复制2份)
int package_dp(vector<int>& w, vector<int>& v, int m, int n) {
vector< vector<int> > vec(n+1, vector<int>(m+1, 0));//vec[n+1][m+1]
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (w[i] > j)
vec[i][j] = vec[i - 1][j];
else {
int tmp1 = v[i] + vec[i - 1][j - w[i]];//放入i
int tmp2 = vec[i - 1][j];//不放i
vec[i][j] = tmp1 > tmp2 ? tmp1 : tmp2;
}
}
}
return vec[n][m];
}
int main(){
int N,T;
while(cin>>N>>T){
vector<vector<int>> vv(N,vector<int>(3,0));
vector<int> w;
vector<int> v;
int res;
int a,b,c=0;
w.push_back(0);
v.push_back(0);
for(int i = 0;i<N;i++){
cin>>vv[i][0]>>vv[i][1]>>vv[i][2];
for(int j = 0;j<vv[i][2];j++){
w.push_back(vv[i][0]);
v.push_back(vv[i][1]);
}
c += vv[i][2];
}
res = package_dp(w,v,T,c);
cout<<res<<endl;
}
system("pause");
return 0;
}
2019年8月4号