描述 | |
---|---|
知识点 | 数组,函数,指针,位运算,结构体 |
运行时间限制 | 10M |
内存限制 | 128 |
输入 |
输入说明 |
输出 |
输出整理后的结果 |
样例输入 | 2 3 4 5 5 7 |
样例输出 | 4 5 5 7 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
int m, n;
cin >> m >> n;
map<int, int> data;
while (m > 0)
{
int key, value;
cin >> key >> value;
if (data.find(key) == data.end())
{
data.insert(make_pair(key, value));
}
m--;
}
int preKey, preValue;
int curKey, curValue;
map<int, int>::iterator it = data.begin();
preKey = it->first;
preValue = it->second;
it++;
cout << preKey << " " << preValue << endl;
for (it; it != data.end(); it++)
{
curKey = it->first;
curValue = it->second;
if (it->first - preKey > 1)
{
for (int i = 1; i < it->first - preKey; i++)
{
cout << preKey + i << " " << preValue + (curValue - preValue) / (curKey - preKey)*i << endl;
}
}
cout << curKey << " " << curValue << endl;
preKey = curKey;
preValue = curValue;
}
return 0;
}