codeforces round #236 div.2 B
来源:互联网 发布:面试题php了解多少 编辑:程序博客网 时间:2024/05/01 00:22
题目链接:http://codeforces.com/contest/402/problem/B
暴力求解,第一次做没有考虑到剪切后树的高度不能为零和负值,WA了,改掉后就OK了
///2014.3.16 - 2014.3.18///codeforces round #236 div.2///B#include <cstdio>#include <iostream>using namespace std;int n;int k;int tree[1050];int numOfNotCutTree;int numNotCut;bool init(){ scanf("%d%d",&n,&k); for(int i=0 ; i<n ; i++){ scanf("%d",&tree[i+1]); }}bool find(int &numOfNotCutTree,int &numNotCut){ numOfNotCutTree = 1; numNotCut = 1110; for(int i=1 ; i<=n ; i++){ int num = 0; bool flag = false; for(int j=1 ; j<=n ; j++){ if( tree[j]-tree[i] != (j-i)*k ){ num++; } if( tree[i]+(j-i)*k<=0 ){ ///修剪后树的高度不能为负 flag = true; break; } } if(flag) continue; if( num<numNotCut ){ numOfNotCutTree = i; numNotCut = num; } } return true;}bool out(int numOfNotCutTree,int numNotCut){ printf("%d\n",numNotCut ); for(int i=1 ; i<=n ; i++){ if( tree[i]-tree[numOfNotCutTree] != (i-numOfNotCutTree)*k ){ int l = -tree[i]+(tree[numOfNotCutTree]+(i-numOfNotCutTree)*k); if( l<0 ){ printf("- %d %d\n",i,-l ); } else{ printf("+ %d %d\n",i,l ); } } }}int main(){ // freopen("in","r",stdin); // freopen("out","w",stdout); init(); find(numOfNotCutTree,numNotCut); out(numOfNotCutTree,numNotCut); return 0;}
0 0
- Codeforces Round #236 (Div. 2)B
- Codeforces round #236Div.2--A;B
- Codeforces Round #236 (Div. 2)------A,B
- codeforces round #236 div.2 B
- Codeforces Round #236 (Div. 2) B. Trees in a Row
- codeforces Round # 236(DIV 2)B. Trees in a Row
- Codeforces Round #236 (Div. 2) B. Trees in a Row
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #134 (Div. 2)B. Airport
- Codeforces Round #170 (Div. 2) problem B
- Codeforces Round #173 (Div. 2) Problem B
- Codeforces Round #181 (Div. 2) B. Coach
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #171 (Div. 2) B
- Codeforces Round #169 (Div. 2) B题
- Codeforces Round #188 (Div. 2) B题
- Codeforces Round #192 (Div. 2) B
- Codeforces Round #203 (Div. 2) B. Resort
- hibernate的继承关系映射(一)
- 人在旅途
- mapreduce实现reduce端表关联
- 第六章作业part2
- awk 正则表达式
- codeforces round #236 div.2 B
- android listview 属性介绍
- 2.Unix高级编程-----ls的实现
- 谈disruptor的单线程数据库操作
- 初学菜鸟的学习日记——继续低端(代理模式设计)
- [LeetCode] Swap Nodes in Pairs
- 【菜鸟学WCF】Wcf消息交换模式
- codeforces round #236 div.2 C
- apue.h包头找不到的问题