CCF 201509-1 Series segment (water problem)

Source: Internet
Author: User
Tags cmath

Problem DescriptionGiven an integer series, the sequence of the longest consecutive integers in the series is counted as a paragraph, and the number of paragraphs in the question series? Input FormatThe first line of the input contains an integer n, which represents the number of integers in the sequence.
The second line contains n integers a1, a2, ..., an, which represents the given number of columns, separated by a space between adjacent integers. output FormatOutputs an integer that indicates that a given sequence has more than one segment. Sample Input8
8 8 8 0 12 12 8 0 Sample Output5 Sample Description8 8 8 is the first paragraph, 0 is the second paragraph, 12 12 is the third paragraph, the penultimate second integer 8 is the fourth paragraph, and the last 0 is the fifth paragraph. Measuring use case size and conventions1≤n≤1000,0≤ai≤1000. Analysis: Sweep once. The code is as follows:
#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <cstdio> #include <string> #include < cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include < queue> #include <algorithm> #include <vector> #include <map> #include <cctype> #include < cmath> #include <stack> #define FREOPENR freopen ("In.txt", "R", stdin) #define FREOPENW freopen ("OUT.txt", "W",  STDOUT) using namespace Std;typedef long Long ll;typedef pair<int, int> p;const int inf = 0x3f3f3f3f;const double inf = 0x3f3f3f3f3f3f;const LL LNF = 0x3f3f3f3f3f3f;const Double PI = ACOs ( -1.0); const double EPS = 1e-8;const int maxn = 1e4 + 5;const int mod = 1e9 + 7;const int dr[] = {-1, 0, 1, 0};const int dc[] = {0, 1, 0, -1};const char *hex[] = {"0000", "00 "0010", "0011", "0100", "0101", "0110", "0111", "N", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};int N , M;const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, to, 31};const int monn[] = {0, h, H, a, A, a, a, a, a, a, a, a, 31};inline int Min (int a, int b) {return a < b? A:b;} inline int Max (int a, int b) {return a > b a:b;} inline ll Min (ll A, ll b) {return a < b a:b;} inline ll Max (ll A, ll b) {return a > b a:b;} inline bool Is_in (int r, int c) {return R >= 0 && r < n && C >= 0 && C < m;}        int main () {while (scanf ("%d", &n) = = 1) {int ans = 1, x, y;        scanf ("%d", &x);            for (int i = 1; i < n; ++i) {scanf ("%d", &y);            if (Y! = x) ++ans;        x = y;    } printf ("%d\n", ans); } return 0;}

CCF 201509-1 Series segment (water problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.