codeforces 339A.Helpful Maths B.Xenia and Ringroad 两水题

简介: .题意就是把字符串里面的数字按增序排列,直接上代码。

A.题意就是把字符串里面的数字按增序排列,直接上代码。


#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
    char s[1005];
    int num[105];
    while (scanf("%s" , s) != EOF)
    {
        int l = strlen(s);
        int t = 0;
        int cnt = 0;
        for (int i = 0; i <= l; i++)
        {
            if (s[i] == '+' || !s[i])
            {
                num[++cnt] = t;
                t = 0;
                continue;
            }
            t = t*10 + s[i]-'0';
        }
        sort(num+1, num+cnt+1);
        for (int i = 1; i < cnt; i++)
            printf("%d+", num[i]);
        printf("%d\n", num[cnt]);
    }
    return 0;
}



B.题意,有n个房子顺时针排成一圈,标号从1到n,只能顺时针走,要按次序到达规定的位置,从一个房子到旁边的房子需要1单位的时间,求总共要多长时间(注意要用64位整形)


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
using namespace std;
int a[100005];
int main()
{
    int n, m;
    __int64 ans;
    a[0] = 1;
    while (scanf("%d %d", &n, &m) != EOF)
    {
        ans = 0;
        for (int i = 1; i <= m; i++)
        {
            scanf("%d", &a[i]);
            if (a[i] >= a[i-1])
                ans += (__int64)(a[i] - a[i-1]);
            else
                ans += (n-a[i-1]+a[i]);
        }
        printf("%I64d\n", ans);
    }
    return 0;
}
目录
相关文章
|
9月前
codeforces 322 B Ciel and Flowers
有红绿蓝三种颜色的画,每种拿三朵可以组成一束花,或者各拿一朵组成花束,告诉你每种花的数目,求出可能组成最多的花束。 如果你的代码过不了,考虑一下 8 8 9这种组合。 因为数据量很大,我的思想就是局部和总体采用不同的策略。
34 0
|
9月前
codeforces 312
A. Whose sentence is it?
31 0
|
9月前
codeforces 304A. Pythagorean Theorem II
给你一个n,计算出1 ≤ a ≤ b ≤ c ≤ n.使得由abc构成的三角形满足勾股定理,c为斜边。 没有简单的方法,直接爆力,但是要注意,有些abc满足勾股定理的表达式,但不一定是三角形,所以要判断一下,根据三角形三边的性质,两边之和大于第三边,两边之差小于第三边。
38 0
|
9月前
|
C++
codeforces 305 C. Ivan and Powers of Two
我的思路是这样的,由2^a+2^a = 2^(a+1)可知,如果有两个连续的数a,我们可以把他们合并为a+1放入集合中,使集合中没有重复的数,我可以用stl里的set。如果想要满足题目中的要求,集合中必须有最大那个数个元素,缺多少就可以计算出来了。
18 0
C - Rumor CodeForces - 893C
C - Rumor CodeForces - 893C
68 0
|
人工智能
Codeforces 777C Alyona and Spreadsheet
C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard ...
1140 0
Codeforces 591B Rebranding
B. Rebranding time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output ...
834 0