腾讯后台 1 1 0 1 0.1,求第三题思路和第五题题目
第三题想法是排序,然后从最大值平均分两组,如果某一组超过一半,就剩下的给数量少的组,然而一个都没过。。。。。
  
 
 #腾讯##笔试题目#
     第五题没看到题目 
 //第二题
#include "stdafx.h"
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <bitset>
#include <stack>
using namespace std;
bool cmp(pair<int, int> p1, pair<int, int> p2)
{
	if (p1.second <= p2.second)
	{
		return true;
	}
	else
	{
		return false;
	}
}
int main1()
{
	int nNums;
	cin >> nNums;
	vector<pair<int,int>> vecNums;
	int nA, nB;
	while (nNums--)
	{
		cin >> nA >> nB;
		vecNums.push_back(make_pair(nA,nB));
	}
	sort(vecNums.begin(), vecNums.end(),cmp);
	int nMIN = INT_MIN;
	int nCount = vecNums.size() - 1;
	for (size_t i = 0; i <= nCount; )
	{
		--vecNums[i].first;
		--vecNums[nCount].first;
		nMIN = max(vecNums[i].second+vecNums[nCount].second,nMIN);
		if (vecNums[i].first == 0)
		{
			++i;
		}
		if (vecNums[nCount].first == 0)
		{
			--nCount;
		}
	}
	cout << nMIN << endl;
	system("pause");
	return 0;
}
//第四题
// IT笔试.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <bitset>
#include <stack>
#include <limits.h>
using namespace std;
int main()
{
	int n, k;
	int nTem;
	cin >> n >> k;
	vector<int> vecNums;
	while (n--)
	{
		cin >> nTem;
		vecNums.push_back(nTem);
	}
	sort(vecNums.begin(), vecNums.end());
	int i = 0;
	int nMin;
	while (k--)
	{
		if (vecNums[vecNums.size() - 1] != 0)
		{
			while (vecNums[i] == 0)
			{
				++i;
			}
			nMin = vecNums[i];
			cout << nMin << endl;
			for (size_t j = i; j < vecNums.size(); j++)
			{
				vecNums[j] -= nMin;
			}
		}
		else
		{
			cout << 0 << endl;
		}
	}
	system("pause");
    return 0;
}
  查看3道真题和解析
查看3道真题和解析