十七周周赛小节

最近考试考的,好凌乱啊。。今天的周赛好碎啊。。。哎,这个感觉不太好啊、、

上来想抢fb做c结果,悲剧了啊,错了两遍才搞明白什么意思啊。。。结果感觉有点费事就放了一下,结果就卡死了啊。。没来得及再做啊。。。sad、、、

先写几道啊,其他的等到考试结束之后继续磕吧。。。

简单说一下啊:

A,比较水啊,就是给你长方体一个顶点上的三个面的面积,让你求长方体的所有边的边长。

A. Parallelepiped
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.

Input

The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.

Output

Print a single number — the sum of all edges of the parallelepiped.

Sample test(s)
input
1 1 1
output
12
input
4 6 6
output
28
Note

In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.


#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-7
#define M 100100
#define LL __int64
#define INF 0x3f3f3f3f
#define PI 3.1415926535898


using namespace std;

int main()
{
    int a, b, c;
    while(cin >>a>>b>>c)
    {
        int x, y, z;
        x = (int)sqrt(a*b/(c*1.0));
        y = (int)sqrt(b*c/(a*1.0));
        z = (int)sqrt(a*c/(b*1.0));
        cout<<4*(x+y+z)<<endl;
    }
    return 0;
}

B:想复杂了啊,一直在鼓捣预处理怕超时,结果竟然这么简单,伤不起啊。。。

B. Array
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You've got an array a, consisting of n integers: a1, a2, ..., an. Your task is to find a minimal by inclusion segment [l, r] (1 ≤ l ≤ r ≤ n)such, that among numbers al,  al + 1,  ...,  ar there are exactly k distinct numbers.

Segment [l, r] (1 ≤ l ≤ r ≤ n; l, r are integers) of length m = r - l + 1, satisfying the given property, is called minimal by inclusion, if there is no segment [x, y] satisfying the property and less then m in length, such that 1 ≤ l ≤ x ≤ y ≤ r ≤ n. Note that the segment [l, r]doesn't have to be minimal in length among all segments, satisfying the given property.

Input

The first line contains two space-separated integers: n and k (1 ≤ n, k ≤ 105). The second line contains n space-separated integersa1, a2, ..., an — elements of the array a (1 ≤ ai ≤ 105).

Output

Print a space-separated pair of integers l and r (1 ≤ l ≤ r ≤ n) such, that the segment [l, r] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them.

Sample test(s)
input
4 2
1 2 2 3
output
1 2
input
8 3
1 1 2 2 3 3 4 5
output
2 5
input
7 4
4 7 7 4 7 4 7
output
-1 -1
Note

In the first sample among numbers a1 and a2 there are exactly two distinct numbers.

In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.

In the third sample there is no segment with four distinct numbers.

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-7
#define M 1001000
#define LL __int64
#define INF 0x3f3f3f3f
#define PI 3.1415926535898


using namespace std;

int f[M];
int dp[M];
int vi[M];
int main()
{
    LL i;
    LL n, k;
    while(cin >>n>>k)
    {
        for(i = 1; i <= n; i++)
            cin >>f[i];
        memset(vi , 0 , sizeof(vi));
        int sum = 0;
        int q;
        vi[f[1]] = 1;
        sum = 1;
        for(i = 2; i <= n; i++)
        {
            if(!vi[f[i]])
            {
                sum ++;
                vi[f[i]] = 1;
            }
            else
            {
                vi[f[i]]++;
            }
            if(sum == k)
            {
                q = i;
                break;
            }
        }
        int p;
        for(i = 1; i <= n; i++)
        {
            if(vi[f[i]] ==1)
            {
                p = i;
                break;
            }
            else
                vi[f[i]]--;
        }
        if(k == 1)
            cout<<"1 1"<<endl;
        else if(sum < k)
            cout<<"-1 -1"<<endl;
        else
            cout<<p<<" "<<q<<endl;
    }
    return 0;
}

C题好不容易搞懂的题意,结果还是没做成功啊。。哎。。。

就是一个模拟栈的过程,求出各个自己中最多的[]的情况,然后照着原来的顺序直接输出就OK了啊。。。括号匹配啊。。

A. Bracket Sequence
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

bracket sequence is a string, containing only characters "(", ")", "[" and "]".

correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()[]", "([])" are correct (the resulting expressions are: "(1)+[1]", "([1+1]+1)"), and "](" and "[" are not. The empty string is a correct bracket sequence by definition.

substring s[l... r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2... s|s| (where |s| is the length of string s) is the string slsl + 1... srThe empty string is a substring of any string by definition.

You are given a bracket sequence, not necessarily correct. Find its substring which is a correct bracket sequence and contains as many opening square brackets «[» as possible.

Input

The first and the only line contains the bracket sequence as a string, consisting only of characters "(", ")", "[" and "]". It is guaranteed that the string is non-empty and its length doesn't exceed 105 characters.

Output

In the first line print a single integer — the number of brackets «[» in the required bracket sequence. In the second line print the optimal sequence. If there are more than one optimal solutions print any of them.

Sample test(s)
input
([])
output
1
([])
input
(((
output
0
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-7
#define M 1001000
#define LL __int64
#define INF 0x3f3f3f3f
#define PI 3.1415926535898


using namespace std;

char s[M];
char str[M];
int f[M];
int vi[M];
int main()
{
    int i, j, k;
    while(cin >>s)
    {
        k = strlen(s);
        memset(vi , -1 , sizeof(vi));
        int top = 0;
        int t = 0;
        for(i = 0; i < k; i++)
        {
            if(s[i] == '(')
            {
                str[++top] = '(';
                f[++t] = i;
            }
            else if(s[i] == ')')
            {
                if(str[top] == '(')
                {
                    vi[i] = f[t];
                    vi[f[t]] = i;
                    top--;
                    t--;
                }
                else
                {
                    str[++top] = ')';
                    f[++t] = i;
                }
            }
            else if(s[i] == '[')
            {
                str[++top] = '[';
                f[++t] = i;
            }
            else if(s[i] == ']')
            {
                if(str[top] == '[')
                {
                    vi[i] = f[t];
                    vi[f[t]] = i;
                    top--;
                    t--;
                }
                else
                {
                    str[++top] = ']';
                    f[++t] = i;
                }
            }
        }
        int x, y;
        int _max = 0;
        int flat1 = 0;
        for(i = 0; i < k; )
        {
            int sum = 0;
            int flat = 0;
            if(vi[i]!=-1)
            {
                flat1 = 1;
                for(j = i; vi[j]!= -1; j++)
                {
                    if(s[j] == '[')
                        sum ++;
                    flat = 1;
                }
            }
            if(sum > _max)
            {
                _max = sum;
                x = i;
                y = j;
            }
            if(flat)
                i = j;
            else
                i++;
        }
        if(flat1)
        {
            cout<<_max<<endl;
            for(i = x; i < y; i++)
                cout<<s[i];
            cout<<endl;
        }
        else
            cout<<"0"<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值