CodeForces 723

来源:互联网 发布:阿里云电视盒子破解 编辑:程序博客网 时间:2024/06/06 04:44

723A The New Year: Meeting Friends

题目大意:数轴上有3个点x1<x2<x3,求一个点x0,最小化|x1x0|+|x2x0|+|x3x0|
题解:显然,x0肯定在[x1,x3],否则不是最优解,故化简得:x3x1+|x2x0|,故x0=x2时解最小为x3x1

#include <cstdio>#include <algorithm>using namespace std;int main() {    int x[3];    scanf("%d%d%d", x, x + 1, x + 2);    sort(x, x + 3);    printf("%d", x[2] - x[0]);    return 0;}

723B Text Document Analysis

题目大意:找出在括号外的最长单词的长度和括号内的单词个数
题解:简单模拟一下就好了

#include <stdio.h>int max(int a, int b) { return a > b ? a : b; }char s[256];int main() {    int n, i, l = 0, p = 0, cnt = 0, ans1 = 0, ans2 = 0;    scanf("%d%s", &n, s);    s[n] = 0;    for (i = 0; i <= n; ++i) {        if ('A' <= s[i] && s[i] <= 'Z' ||            'a' <= s[i] && s[i] <= 'z')            ++l;        else {            if (l) {                if (p) ++ans2;                else ans1 = max(ans1, l);                l = 0;            }            if (s[i] == '(') ++p;            else if (s[i] == ')') --p;        }    }    printf("%d %d", ans1, ans2);    return 0;}
0 0