Last active
September 5, 2017 05:56
-
-
Save zhanglaplace/4e6f68c59cf72a9b7c9e0034d63deef9 to your computer and use it in GitHub Desktop.
4offer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************* | |
度度熊想去商场买一顶帽子,商场里有N顶帽子,有些帽子的价格可能相同。度度熊想买一顶价格第三便宜的帽子,问第三便宜的帽子价格是多少? | |
输入描述: | |
首先输入一个正整数N(N <= 50),接下来输入N个数表示每顶帽子的价格(价格均是正整数,且小于等于1000) | |
输出描述: | |
如果存在第三便宜的帽子,请输出这个价格是多少,否则输出-1 | |
输入例子1: | |
10 | |
10 10 10 10 20 20 30 30 40 40 | |
输出例子1: | |
30 | |
*****************************/ | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int main(){ | |
int n ; | |
cin >>n; | |
vector<int>prices(n,0); | |
for(int i = 0 ; i < n ; ++i){ | |
cin>>prices[i]; | |
} | |
sort(prices.begin(),prices.end()); | |
prices.erase(unique(prices.begin(),prices.end()),prices.end()); | |
if(prices.size()< 3) | |
cout<<-1<<endl; | |
else | |
cout<<prices[2]<<endl; | |
return 0; | |
} | |
/********************************* | |
一个数轴上共有N个点,第一个点的坐标是度度熊现在位置,第N-1个点是度度熊的家。现在他需要依次的从0号坐标走到N-1号坐标。 | |
但是除了0号坐标和N-1号坐标,他可以在其余的N-2个坐标中选出一个点,并直接将这个点忽略掉,问度度熊回家至少走多少距离? | |
输入描述: | |
输入一个正整数N, N <= 50。 | |
接下来N个整数表示坐标,正数表示X轴的正方向,负数表示X轴的负方向。绝对值小于等于100 | |
输出描述: | |
输出一个整数表示度度熊最少需要走的距离。 | |
输入例子1: | |
4 | |
1 4 -1 3 | |
输出例子1: | |
4 | |
************************************/ | |
#include <iostream> | |
using namespace std; | |
int main(){ | |
int n ; | |
cin >> n; | |
vector<int>dis(n,0); | |
for(int i = 0 ; i < n ; ++i){ | |
cin>>dis[i]; | |
} | |
int max_val = 0; | |
int sum = abs(dis[n-1]-dis[n-2]); | |
int index = 0; | |
for(int i = 1; i < n-1;++i){ | |
int temp = abs(dis[i+1]-dis[i])+abs(dis[i]-dis[i-1])-abs(dis[i+1]-dis[i-1]);//最大的间隔 | |
if(temp > max_val){ | |
max_val = temp; | |
index = i; | |
} | |
sum += abs(dis[i]-dis[i-1]); | |
} | |
cout<<sum-max_val<<endl; | |
return 0; | |
} | |
/******************************************************* | |
三维空间中有N个点,每个点可能是三种颜色的其中之一,三种颜色分别是红绿蓝,分别用'R', 'G', 'B'表示。 | |
现在要找出三个点,并组成一个三角形,使得这个三角形的面积最大。 | |
但是三角形必须满足:三个点的颜色要么全部相同,要么全部不同。 | |
输入描述: | |
首先输入一个正整数N三维坐标系内的点的个数.(N <= 50) | |
接下来N行,每一行输入 c x y z,c为'R', 'G', 'B' 的其中一个。x,y,z是该点的坐标。(坐标均是0到999之间的整数 | |
输出描述: | |
输出一个数表示最大的三角形面积,保留5位小数。 | |
输入例子1: | |
5 | |
R 0 0 0 | |
R 0 4 0 | |
R 0 0 3 | |
G 92 14 7 | |
G 12 16 8 | |
输出例子1: | |
6.00000 | |
*******************************************************/ | |
#include <iostream> | |
#include <algorithm> | |
#include <string> | |
#include <cmath> | |
#include <iomanip> | |
using namespace std; | |
int main(){ | |
int n ; | |
cin>>n; | |
vector<vector<int> >pt(n,vector<int>(3,0)); | |
vector<char>c_t(n); | |
for(int i = 0 ; i < n;++i){ | |
cin>>c_t[i]>>pt[i][0]>>pt[i][1]>>pt[i][2]; | |
} | |
double max_d = 0.0; | |
for(int i = 0 ; i < n-2;++i){ | |
for(int j = i+1; j < n-1;++j){ | |
for(int k = j+1;k < n;++k){ | |
if((c_t[i] == c_t[j] && c_t[i] == c_t[k])||(c_t[i]!=c_t[j] && c_t[i]!=c_t[k] && c_t[k]!=c_t[j])){ | |
double a = sqrt(pow(pt[i][0]-pt[j][0],2)+pow(pt[i][1]-pt[j][1],2)+pow(pt[i][2]-pt[j][2],2)); | |
double b = sqrt(pow(pt[i][0]-pt[k][0],2)+pow(pt[i][1]-pt[k][1],2)+pow(pt[i][2]-pt[k][2],2)); | |
double c = sqrt(pow(pt[j][0]-pt[k][0],2)+pow(pt[j][1]-pt[k][1],2)+pow(pt[j][2]-pt[k][2],2)); | |
double l = (a+b+c)/2.0; | |
double temp = sqrt(l*(l-a)*(l-b)*(l-c)); | |
if(temp > max_d) | |
max_d = temp; | |
} | |
} | |
} | |
} | |
cout<<fixed<<setprecision(5)<<max_d<<endl; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment