CodeForces - 402B Trees in a Row (暴力)
题意:给定n个数,要求修改其中最少的数,使得这n个数满足ai + 1 - ai = k。
分析:
暴力,1000*1000。
1、这n个数,就是一个首项为a1,公差为k的等差数列。k已知,如果确定了a1,就能确定整个数列。
2、1 ≤ ai ≤ 1000,因此,可以从1~1000中枚举a1,将形成的数列与给定的数列比较,统计两数列对应下标中不同数字的个数。
3、不同数字的个数最少的那个数列就是最终要修改成的数列,然后输出对应下标的那个数的变化值即可。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int a[MAXN];
int main(){
int n, k;
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++i){
scanf("%d", &a[i]);
}
int id = 0;
int _min = 0x7f7f7f7f;
for(int i = 1; i <= 1000; ++i){
int cnt = 0;
for(int j = 1; j <= n; ++j){
if(a[j] != i + (j - 1) * k){
++cnt;
}
}
if(cnt < _min){
_min = cnt;
id = i;
}
}
printf("%d\n", _min);
for(int i = 1; i <= n; ++i){
if(a[i] != id + (i - 1) * k){
if(a[i] > id + (i - 1) * k){
printf("- %d %d\n", i, a[i] - id - (i - 1) * k);
}
else{
printf("+ %d %d\n", i, id + (i - 1) * k - a[i]);
}
}
}
return 0;
}
CodeForces - 402B Trees in a Row (暴力)的更多相关文章
- codeforces B. Trees in a Row 解题报告
题目链接:http://codeforces.com/problemset/problem/402/B 题目意思:给出n个数和公差k,问如何调整使得ai + 1 - ai = k.(1 ≤ i < ...
- B. Trees in a Row(cf)
B. Trees in a Row time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Gym 100002 C "Cricket Field" 暴力
"Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...
- Codeforces Gym 100513M M. Variable Shadowing 暴力
M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...
- Codeforces Gym 100513G G. FacePalm Accounting 暴力
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
- Codeforces 839A Arya and Bran【暴力】
A. Arya and Bran time limit per test:1 second memory limit per test:256 megabytes input:standard inp ...
- Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力
Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consist ...
- Codeforces Beta Round #3 B. Lorry 暴力 二分
B. Lorry 题目连接: http://www.codeforces.com/contest/3/problem/B Description A group of tourists is goin ...
- codeforces 673C C. Bear and Colors(暴力)
题目链接: C. Bear and Colors time limit per test 2 seconds memory limit per test 256 megabytes input s ...
随机推荐
- 「USACO08JAN」电话线Telephone Lines
传送门 Luogu 解题思路 考虑二分,每次把大于二分值的边的权设为1,小于等于的设为0,如果最短路<=k则可行,记得判无解 细节注意事项 咕咕咕 参考代码 #include <algor ...
- String类与StringBuffer类
String类与StringBuffer类 一.String类和StringBuffer类的区别 String类是不可变类,新建的对象为不可变对象(String类的内容和长度是固定的),一旦被创建 ...
- php注册与登录
一.注册 1.注册界面 <!DOCTYPE html><html lang="en"><head> <meta charset=" ...
- [Struts]Token 使用及原理
Struts Token 使用 1,先在一个Action中,调用saveToken(HttpServletRequest request)方法.然后转向带有表单的JSP页面. 2,在JSP页面提交 ...
- Python面试2未完待续
Python面试重点(基础篇) 注意:只有必答题部分计算分值,补充题不计算分值. 第一部分 必答题(每题2分) 简述列举了解的编程语言及语言间的区别? c语言是编译型语言,运行速度快,但翻译时间长py ...
- Arch-base-vs-iso
Arch-base-vs-iso 通常绝大多数的Linux分发版的iso镜像本身(*.iso文件都有约2Gb上下)都可以直接启动电脑并运行完整的Linux桌面系统. 极少数的Linux发行版仅提供命令 ...
- 解题报告:luogu P5020(NOIP 2018 D1T2)
题目链接:P5020 货币系统 \(NOIP\) 的题挺精华啊. 开始感觉自己有隐约的思路,但感觉太暴力,连数据范围都没看,就去看题解了(不会啊). 听说是\(dp\)又是一惊,直接弃疗. 其实只是个 ...
- 多个Activity跳转的小结
第一个例子:demo1 Main—>SecondActivity—>Main 从流程上看就是从Main跳转到SecondActivity,再从SecondActivity返回到Main.也 ...
- Day5 - F - 食物链 POJ - 1182
动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C吃A.现有N个动物,以1-N编号.每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种.有人用两种说法 ...
- CentOS 6.5(x86_32)下安装Oracle 10g R2
一.硬件要求 1.内存 & swap Minimum: 1 GB of RAMRecommended: 2 GB of RAM or more 检查内存情况 # grep MemTotal / ...