CCF认证真题-(201509-1)-数列分段

 1 #include <iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     ios::sync_with_stdio(false);
 6     cin.tie(0);
 7
 8     int n;
 9     cin >> n;
10     int pre;
11     cin >> pre;
12     int ans = 1;
13     for (int i = 1; i < n; i++) {
14         int x;
15         cin >> x;
16         if (x != pre) {
17             ans++;
18             pre = x;
19         }
20     }
21     cout << ans << endl;
22     return 0;
23 }

原文地址:https://www.cnblogs.com/AntonLiu/p/11165508.html

时间: 2024-08-04 01:40:23

CCF认证真题-(201509-1)-数列分段的相关文章

CCF认证真题-(201312-1)-出现次数最多的数

1 #include <iostream> 2 using namespace std; 3 int arr[10005]; 4 int main() 5 { 6 ios::sync_with_stdio(false); 7 cin.tie(0); 8 int n; 9 cin >> n; 10 int x, maxn = 0; 11 for (int i = 0; i < n; i++) { 12 cin >> x; 13 maxn = x > maxn

CCF认证真题-(201312-2)-ISBN号码(模拟)

#include <iostream> #include <algorithm> using namespace std; int arr[10005]; int toNum(char ch) {return ch - '0';} int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int num = toNum(s[0]) + toNum(s[2]) * 2 + toNum

CCF认证真题-(201409-2)-画图(暴力)

1 #include <iostream> 2 #include <algorithm> 3 #include <set> 4 using namespace std; 5 6 bool vis[105][105]{false}; 7 int main() 8 { 9 ios::sync_with_stdio(false); 10 cin.tie(0); 11 int n; 12 cin >> n; 13 int x1, y1, x2, y2, s = 0;

CCF认证真题-(201412-2)-Z字形扫描

1 #include <iostream> 2 using namespace std; 3 int arr[505][505]; 4 bool flag; 5 int n; 6 void printComp(int x1, int y1, int x2, int y2) 7 { 8 int i = x1, j = y1; 9 if (x1 == n && x2 == n) { 10 cout << arr[n][n] << endl; 11 retur

CCF认证真题-(201509-2)-日期计算

1 #include <iostream> 2 using namespace std; 3 int month[2][13] {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, 4 {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}}; 5 6 bool isLeap(int y) 7 { 8 return y % 400 == 0 || (y % 4 == 0 &&

ccf历年真题(截至2015年9月)

问题描述 试题编号: 201509-1 试题名称: 数列分段 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 给定一个整数数列,数列中连续相同的最长整数序列算成一段,问数列中共有多少段? 输入格式 输入的第一行包含一个整数n,表示数列中整数的个数. 第二行包含n个整数a1, a2, …, an,表示给定的数列,相邻的整数之间用一个空格分隔. 输出格式 输出一个整数,表示给定的数列有多个段. 样例输入 8 8 8 8 0 12 12 8 0 样例输出 5 样例说明 8 8

CCF考试真题题解

CCF考试认证:题解参考博客http://blog.csdn.net/u014578266/article/details/45221841 问题描述 试题编号: 201503-1 试题名称: 图像旋转 时间限制: 5.0s 内存限制: 256.0MB 问题描述: 问题描述 旋转是图像处理的基本操作,在这个问题中,你需要将一个图像逆时针旋转90度. 计算机中的图像表示可以用一个矩阵来表示,为了旋转一个图像,只需要将对应的矩阵旋转即可. 输入格式 输入的第一行包含两个整数n, m,分别表示图像矩阵

ccf认证模拟题之三---最大的矩形

问题描述 在横轴上放了n个相邻的矩形,每个矩形的宽度是1,而第i(1 ≤ i ≤ n)个矩形的高度是hi.这n个矩形构成了一个直方图.例如,下图中六个矩形的高度就分别是3, 1, 6, 5, 2, 3. 请找出能放在给定直方图里面积最大的矩形,它的边要与坐标轴平行.对于上面给出的例子,最大矩形如下图所示的阴影部分,面积是10. 输入格式 第一行包含一个整数n,即矩形的数量(1 ≤ n ≤ 1000). 第二行包含n 个整数h1, h2, … , hn,相邻的数之间由空格分隔.(1 ≤ hi ≤

CCF真题之数列分段

201509-1  数列分段 问题描述 给定一个整数数列,数列中连续相同的最长整数序列算成一段,问数列中共有多少段? 输入格式 输入的第一行包含一个整数n,表示数列中整数的个数. 第二行包含n个整数a1, a2, …, an,表示给定的数列,相邻的整数之间用一个空格分隔. 输出格式 输出一个整数,表示给定的数列有多个段. 样例输入 8 8 8 8 0 12 12 8 0 样例输出 5 样例说明 8 8 8是第一段,0是第二段,12 12是第三段,倒数第二个整数8是第四段,最后一个0是第五段. 评