| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
用python又生成测试了十几组数据,跟大佬给的代码运行结果都一模一样,上传还是answer wrong 为啥啊?#include <iostream>
#include <vector>
#include <cmath>
int main()
{
int width;//宽度
while (std::cin >> width && width != 0) {
std::vector<std::pair<int, int>> image;//图像RLE序数对
int firstp, secondp;//初始化序数对
// 记录序数对
while (std::cin >> firstp && std::cin >> secondp && firstp != 0 && secondp != 0) {
image.push_back(std::make_pair(firstp, secondp));
}
//适度 解压
std::vector<std::pair<int, int>> edge1;
for (std::vector<std::pair<int, int>>::const_iterator it = image.begin();it != image.end();it++) {
if (it->second / width >= 3) {
edge1.push_back(std::make_pair(it->first, width));
edge1.push_back(std::make_pair(-1, it->second - width * 2));
edge1.push_back(std::make_pair(it->first, width));
}
else edge1.push_back(std::make_pair(it->first, it->second));
}
//完全解压
std::vector<int> edge2;
for (std::vector<std::pair<int, int>>::const_iterator it = edge1.begin();it != edge1.end();it++) {
if (it->first != -1) {
for (int i = 0;i < it->second;++i)edge2.push_back(it->first);
}
else {
for (int i = 0;i < width;++i)edge2.push_back(-1);
for (int i = 0;i < (it->second % (2 * width));++i)edge2.push_back(-1);
//-1的个数:width+pair.second%(2*width)
}
}
//计算
std::vector<int> result1(static_cast<int>(edge2.size()), 0);
int height = static_cast<int>(edge2.size()) / width;//长度
for (int x = 0;x < width;++x) {
for (int y = 0;y < height;++y) {
if (edge2[width * y + x] == -1)continue;
int maxabdiff = 0;
int currentabdiff = 0;
for (int dx = -1;dx <= 1;++dx) {
for (int dy = -1;dy <= 1;++dy) {
if (dy == 0 && dx == 0)continue;
if (!(y + dy >= 0 && x + dx >= 0 && y + dy < height && x + dx < width))continue;
if (edge2[width * (y + dy) + (x + dx)] == -1)continue;
currentabdiff = std::abs(edge2[width * (y + dy) + (x + dx)] - edge2[width * y + x]);
maxabdiff = maxabdiff > currentabdiff ? maxabdiff : currentabdiff;
}
}
result1[width * y + x] = maxabdiff;
}
}
result1.push_back(-2);
//压缩
std::vector<std::pair<int, int>> result2;
int nn = 0;
int lengthedge1 = static_cast<int>(edge1.size());
for (int i = 0;i < lengthedge1;++i) {
if (edge1[i].first != -1) {
int currentlength = 1;
int currentValue = -1;
for (int j = 0;j < edge1[i].second;++j) {
currentValue = result1[nn++];
if (currentValue == result1[nn])currentlength++;
else {
result2.push_back(std::make_pair(currentValue, currentlength));
currentlength = 1;
currentValue = -1;
}
}
if (currentValue != -1)result2.push_back(std::make_pair(currentValue, currentlength - 1));
}
else {
result2.push_back(std::make_pair(0, edge1[i].second));
nn += width + (edge1[i].second % (2 * width));
}
}
result2.push_back(std::make_pair(-2, 1));
//再压缩
std::vector<std::pair<int, int>> result3;
int lengthresult2 = static_cast<int>(result2.size());
for (int i = 0;i < lengthresult2 - 1;) {
int sum = result2[i].second;
while (result2[i].first == result2[i + 1].first) {
i++;
sum += result2[i].second;
}
result3.push_back(std::make_pair(result2[i].first, sum));
i++;
}
//输出结果
std::cout << width << std::endl;
for (std::vector<std::pair<int, int>>::const_iterator it = result3.begin();it != result3.end();it++) {
std::cout << it->first << " " << it->second << std::endl;
}
std::cout << "0 0" << std::endl;
}
std::cout << "0";
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator