NO IMAGE

大疆的題,挺複雜,最起碼描述是的。。。

底下的答案僅供參考,沒有一道是全部AC的。

//兩個小車,走一步能量消耗1,方向為1向右,-1為向左,首先輸入路途長度,然後輸入兩行,每行第一個為小車的能量,第二個位小車起始位置,第三個為方向。求幾個小車可以走出去?
#include <iostream>
#include <vector>
using namespace std;

int Many(vector<int> &ve,int len)
{
if(ve.size() < 6 || len <= 0)
return 0;
int end = 0;
int power_a = ve[0];
int local_a = ve[1];
int direc_a = ve[2];
int power_b = ve[3];
int local_b = ve[4];
int direc_b = ve[5];
while(power_a > 0 || power_b > 0)
{
if(direc_a == direc_b)
{
if(direc_a == 1)
{
if(local_a 1 == local_b && power_b == 0)
{
if(power_a > 1)
{
local_a ;
local_b ;
power_a -= 2;
}
}
if(power_a > 0)
{
local_a ;
power_a–;
}
if(power_b > 0)
{
local_b ;
power_b–;
}
}
else
{
if(local_a 1 == local_b && power_a == 0)
{
if(power_b > 1)
{
local_a–;
local_b–;
power_a -= 2;
}
}
if(power_a > 0)
{
local_a–;
power_a–;
}
if(power_b > 0)
{
local_b–;
power_b–;
}
}
}
else
{
if(local_a < 0 || local_a > len-1)
power_a = 0;
if(local_b < 0 || local_b > len-1)
power_b = 0;
if(abs(local_a – local_b) == 2 && direc_a == 1 && direc_b == -1)
{
power_a -= 2;
power_b -= 2;
}
else
{
if(abs(local_a – local_b) == 1)
{
if(direc_a == 1 && direc_b == -1)
{
local_a–;
local_b ;
power_a -= 2;
power_b -= 2;
}
else
{
local_a –;
local_b ;
power_a –;
power_b ;
}
}
else
{
if(direc_a == -1)
{
local_a –;
power_a–;
}
else
{
local_a ;
power_a–;
}
if(direc_b == -1)
{
local_b –;
power_b–;
}
else
{
local_b ;
power_b–;
}
}
}
}
}
if(local_a < 0 || local_a > len-1)
end ;
if(local_b < 0 || local_b > len-1)
end ;
return end;
}
int main()
{
vector<int> ve;
int len;
cin>>len;
int tmp;
for(int i = 0; i < 6; i)
{
cin>>tmp;
ve.push_back(tmp);
}
cout<<Many(ve,len)<<endl;
}

//一共N種花,插花需要每次選M種,每種R支。第二行輸入每種花個數,求最多有多少種插花方法。
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool fun(vector<int> &ve,int m)
{
int i = ve.size()-1;
int num = 0;
for(; i >= 0; –i)
{
if(ve[i] != 0)
num ;
else
break;
}
if(num < m)
return false;
return true;
}
int Many(vector<int> &ve,int n,int m,int r,int num)
{
if(ve.size() <= 0 || n <= 0 || m <= 0 || r <= 0)
return 0;
int end = 0;
int i = ve.size()-1;
while(fun(ve,m))
{
int size = i;
sort(ve.begin(),ve.end());
for(int j = 0; j < m; j)
{
ve[size] –;
size–;
}
end ;
num -= m;
}
return end;
}
int main()
{
int n,m,r;
cin>>n>>m>>r;
vector<int> ve(n);
int tmp;
int num = 0;
for(int i = 0; i < n; i)
{
cin>>tmp;
tmp /= r;
ve.push_back(tmp);
num = tmp;
}
cout<<Many(ve,n,m,r,num)<<endl;
}

//輸入初始位置和結束位置,以及二維陣列的大小,與其中的元素,為0可以走,為1,其上下左右不能走,如果為2,則該位置的上兩個,下兩個,左兩個,右兩個不能走。以此類推,求最短路徑?

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

vector<int> endpath;
void Get_num(vector<vector<int>> &path,int n,int m)
{
for(int i = 0; i < n; i)
{
for(int j = 0; j < m; j)
{
if(path[i][j] != -2)
{
int tmp = 0;
for(int k = 0; k < path[i][j]; k )
{
tmp = i – k – 1;
if(tmp >= 0)
path[tmp][j] = -2;
else
break;
}
for(int k = 0; k < path[i][j]; k )
{
tmp = i k 1;
if(tmp < n)
path[tmp][j] = -2;
else
break;
}
for(int k = 0; k < path[i][j]; k )
{
tmp = j – k – 1;
if(tmp >= 0)
path[i][tmp] = -2;
else
break;
}
for(int k = 0; k < path[i][j]; k )
{
tmp = j k 1;
if(tmp < m)
path[i][tmp] = -2;
else
break;
}
}
}
}
}
void Less_len(vector<vector<int>> &path,int n,int m,int i,int j,int endi,int endj,int num)
{
path[i][j] = -1;
if(i == endi && j == endj)
endpath.push_back(num);
if(i < n && j < m)
{
if(i – 1 >= 0 && path[i-1][j] == 0)
Less_len(path,n,m,i-1,j,endi,endj,num 1);
else if(i 1 < n && path[i 1][j] == 0)
Less_len(path,n,m,i 1,j,endi,endj,num 1);
else if(j – 1 >= 0 && path[i][j-1] == 0)
Less_len(path,n,m,i,j-1,endi,endj,num 1);
else if(j 1 < m && path[i][j 1] == 0)
Less_len(path,n,m,i,j 1,endi,endj,num 1);
}
}
int Less_len(vector<int> &ve,vector<vector<int>> &path,int n,int m)
{
if(ve.size() <= 0 || path.size() <= 0 || n <= 0 || m <= 0)
return -1;
Get_num(path,n,m);
int num = 0;
Less_len(path,n,m,ve[0],ve[1],ve[2],ve[3],num);

int less = 0;
for(int i = 0; i < endpath.size(); i)
{
if(i == 0)
less = endpath[i];
if(less > endpath[i])
less = endpath[i];
}
return less;
}
int main()
{
int n,m;
vector<int> ve;
int tmp;
cin>>n>>m;
for(int i = 0; i < 4; i)
{
cin>>tmp;
ve.push_back(tmp);
}
vector<vector<int>> path(n);
for(int i = 0; i < n; i)
{
path[i].resize(m);
}
for(int i = 0; i < n; i)
{
for(int j = 0; j < m; j)
{
cin>>tmp;
path[i][j] = tmp;
}
}
cout<<Less_len(ve,path,n,m)<<endl;
return 0;
}

//H的水桶,注水速度X,h處有洞,流水速度Y,S秒以後水深(四捨五入)。
#include <iostream>
using namespace std;

int Time(int H,double x,double y,double h,int s)
{
if(H < 0 || H > 5000 || x < 0 || x > 5000 || h < 0 || h > 5000
|| s < 0 || s > 5000 || h > H)
return -1;
double end = x * s – y * (s – h / x);
if(end >= H)
return H;
int tmp = end * 10;
tmp %= 10;
if(tmp > 4)
return end 1;
return end;
}
int main()
{
int H,s;
double h,x,y;
cin>>H>>x>>y>>h>>s;
cout<<Time(H,x,y,h,s)<<endl;
return 0;
}