zoj 3365 (map容器)

Sample Input

6
5 4 5 2 1 8

Sample Output

3
3 4 5 6 7 8


题意 : 修改最少的数,使得序列变成连续的 。


一个序列连续,那么每个数的值和下标的差值相等 ;  所以先把每个数与自身下标的差值存起来,差值相等最多的就是不需要懂的,其他的都需要改  ;数据太大,要用map容器存 ;
科普几个容器的函数  ;
begin()  ;返回指向容器中第一个元素的迭代器地址 ;
end() ;    返回最后一个元素的后面迭代器地址;注意,不是最后一个元素的地址,而是最后一个元素的后一位的地址 ;
map<int,int>::iterator it    定义迭代器地址,it是一个地址;
 容器 m[i]=a ; 当取下标i时,用it->first ,当取a时,it->second ; it是指向m[i]=a的指针 ;


#include <string>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#define maxn 1500
#define maxe 10000*8
#define inf 1000000000
#define eps 1e-9
using namespace std;




int N;
int main()
{
  //  freopen("input.txt","r",stdin);
    int i,j;
    while( scanf("%d",&N)==1&&N)
    {
        map<int,int> mm;
        for(i=0; i<N; i++)
        {
            int temp;
            scanf("%d",&temp);
            mm[temp-i]++;     //差值存入容器中
        }




        int temp=0;
        int one;          
        for(map<int,int>::iterator it=mm.begin(); it!=mm.end(); it++)
        {
            if(temp<(it->second))    //比较差值的个数,选差值个数最多的
            {
                temp=(it->second);  
                one=(it->first);         //记录差值最多的值,也就是下标;
            }
        }
        printf("%d\n%d",N-temp,one);  
        for(i=1; i<N; i++)
        {
            printf(" %d",one+i);    //输出结果;
        }
        puts("");
    }
    return 0;
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值