zoj 3365
题意 给你一个序列 改变尽可能少的数使其成为公差为一 递增的等差数列
可以将给你的序列减去一个等差数列 即num[i] -= i,若得到的数全部相等, 则说明给你的序列本身就满足条件 则只要寻求num中出现次数最多的数 这些数就是不需要改变的数
/*************************************************************************
> Author: xlc2845 > Mail: xlc2845@gmail.com
> Created Time: 2013年10月26日 星期六 19时15分23秒
************************************************************************/ #include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib> using namespace std;
int num[50050], n;
int main()
{
while(scanf("%d",&n) == 1)
{
for(int i = 0; i < n; i++)
{
scanf("%d",&num[i]);
num[i] -= i;
}
sort(num, num+n);
int temp = num[0], _max = 0, d = 1, result = num[0];
for(int i = 1; i < n; i++)
{
if(num[i] == temp) d++;
else
{
temp = num[i];
if(d > _max)
{
_max = d;
result = num[i-1];
}
d = 1;
}
}
if(d > _max)
{
_max = d;
result = num[n-1];
}
printf("%d\n",n-_max);
printf("%d",result);
for(int i = 1; i < n; i++)
printf(" %d",i+result);
puts("");
}
return 0;
}
zoj 3365的更多相关文章
- zoj 3365 灵活数字规律
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3365 #include <cstdio> #incl ...
- ZOJ 3365 Integer Numbers
Integer Numbers Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origina ...
- TOJ 3365 ZOJ 3232 It's not Floyd Algorithm / 强连通分量
It's not Floyd Algorithm 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte 描述 When a directed grap ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
随机推荐
- python学习day3--python基础
1.python不用声明变量的类型,运行时python自己进行判断 2.尽量不要用“+”去拼接字符串,运行时会每遇到一个“+”就开辟一块内存空间,使用如下方式进行字符串的拼接. msg=''' inf ...
- Linux -Yum 命令详解
yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载RP ...
- crackme_zapline分析
[破文标题]crackme_zapline 分析 [破文作者]CloAk [作者邮箱]@qq.com [作者主页] [破解工具]OD,... [破解平台]Windows --------------- ...
- poi-3.11-beta2-20140822.jar操作excel方法
poi-3.11-beta2-20140822.jar操作excel方法 根据不同类型读取值的方法: // 获取单元格内不同类型的值 public String getValueByType(HSSF ...
- 直接拿来用,最火的.NET开源项目(beta)
转自:http://blog.csdn.net/ltylove2007/article/details/18656971 综合类 微软企业库 微软官方出品,是为了协助开发商解决企业级应用开发过程中所面 ...
- Using LINQ Group By and String.Join() / Aggregate() in Entity Framework 3.5
linq to sql 的时候,有时候需要用到 先group 然后来个 aggregate 串连一下值, 但会总会出错,说不识别 aggregate 或者 string.join 方法 搜遍网络 一 ...
- 【转】Linux杀死fork产生的子进程的僵尸进程defunct
僵尸进程 就是 已经结束,但是还没有清理出去的.用kill -9 $PID 也无法杀死. 所以程序中应该避免出现僵尸进程. 用fork之后,父进程如果没有wait /waitpid 等待子进程的话,子 ...
- 使用rapid-framework自动生成struct2
在JavaWeb的开发中,对数据对象的操作不外乎增删改查,不同的数据对象,其action.service.model.jsp等都比较类似,如果手动去写这些代码,工作量大且非常繁琐.一个心高气傲的程序员 ...
- simple_factory
#include <stdlib.h> #include <iostream> using namespace std; class Product { public: vir ...
- DTCMS视频模版更改,
1.去掉style.css中视频的高度 .video-box{ position:relative; width:100%; height:473px; _clear:both; _display:i ...