CodeForces 670B、HDU 1003、CodeForces 632C

6 篇文章 0 订阅
Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u

 Status

Description

In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.

At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.

Your task is to determine the k-th identifier to be pronounced.

Input

The first line contains two positive integers n and k (1 ≤ n ≤ 100 0001 ≤ k ≤ min(2·109, n·(n + 1) / 2).

The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different.

Output

Print the k-th pronounced identifier (assume that the numeration starts from 1).

Sample Input

Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4

Source

Codeforces Round #350 (Div. 2)

思路就是等差数列前n项和:注意要强制转换longlong 

#include<bits/stdc++.h>
using namespace std;
 int a1[100000+10];
int main()
{
    int n;long long k;
    scanf("%d%lld",&n,&k);

    for(int i=0;i<n;i++) scanf("%d",&a1[i]);
    long long sum=0;
    int flag=0;
    for(int i=1;i<=n;i++){
        sum=(long long)(i+1)*i/2;
        if(sum>k) { flag=i; break; }
        else if(sum==k) { printf("%d\n",a1[i-1]); return 0; }
    }
    long long a=flag*(flag+1)/2;
    long long b=(long long)flag*(flag-1)/2;
    printf("%d\n",a1[k-b-1]);
    return 0;
}






Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u

 Status

Description

Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14. 
 

Input

The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000). 
 

Output

For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases. 
 

Sample Input

    
    
2 5 6 -1 5 4 -7 7 0 6 -1 1 -6 7 -5
 

Sample Output

    
    
Case 1: 14 1 4 Case 2: 7 1 6
 
这道属于有点dp思想的题,原来做过,还是不熟。

用一个一维dp数组,记录到i项的最大值,当和为负数时,从0开始加。

 if(d[i-1]<0) d[i]=a[i];
            else d[i]=d[i-1]+a[i];


#include<bits/stdc++.h>
using namespace std;
#define N 100010
int a[N],d[N];
int main()
{
    int t,k=1;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++) scanf("%d",&a[i]);
        d[0]=a[0];
        for(int i=1;i<n;i++){
            if(d[i-1]<0) d[i]=a[i];
            else d[i]=d[i-1]+a[i];
        }
        int ma=d[0],e=0;
        int mx=ma;
        for(int i=1;i<n;i++){
            if(d[i]>ma) { ma=d[i],e=i; }
        }
        int q=e,o=0;
        for(int i=e;i>=0;i--)
        {
            o+=a[i];
            if(ma==o) { q=i;}
        }
        cout<<"Case "<<k++<<":"<<endl<<ma<<" "<<q+1<<" "<<e+1<<endl;
        if(t) cout<<endl;/*
        printf("Case %d:\n%d %d %d\n",k++,ma,q+1,e+1);
        if(t) printf("\n");*/
    }
    return 0;
}

Time Limit: 3000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u

 Status

Description

You're given a list of n strings a1, a2, ..., an. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.

Given the list of strings, output the lexicographically smallest concatenation.

Input

The first line contains integer n — the number of strings (1 ≤ n ≤ 5·104).

Each of the next n lines contains one string ai (1 ≤ |ai| ≤ 50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104.

Output

Print the only string a — the lexicographically smallest string concatenation.

Sample Input

Input
4
abba
abacaba
bcd
er
Output
abacabaabbabcder
Input
5
x
xx
xxa
xxaa
xxaaa
Output
xxaaaxxaaxxaxxx
Input
3
c
cb
cba
Output
cbacbc

Source

cf题,思路挺好,改进排序的方法。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
bool cmp(string a,string b){
    return a+b<b+a;
}
int main()
{
    string a[50000+1];
    int n;scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,cmp);
    for(int i=0;i<n;i++){
        cout<<a[i];
    }
    return 0;
}

一天做一道题就好,反正现在也没那么功利了,完全靠兴趣。

真正要功利的是应试考研,方法总是有的,但要真的努力与动力。

有时候无论作什么都没那么多理由,但你心中总要有一个信念,而不要掺杂太多思想。

那就是成为大人物的渴望,不再那么渺小吧。梦想有一天真正成为自己想成为的那个人,现在就是不懈地区努力。

未来是什么样真的不知道,但毕竟充满危险压力与残酷,武装好自己,做好自己才是真正现在应该做的事。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值