CodeForces 670B、HDU 1003、CodeForces 632C

来源:互联网 发布:通州淘宝城在哪个位置 编辑:程序博客网 时间:2024/06/01 09:47
Game of Robots
Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u

Submit 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 21 2
Output
1
Input
4 510 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;}






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

Submit 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

25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5
 

Sample Output

Case 1:14 1 4Case 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 100010int 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;}

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

Submit 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
4abbaabacababcder
Output
abacabaabbabcder
Input
5xxxxxaxxaaxxaaa
Output
xxaaaxxaaxxaxxx
Input
3ccbcba
Output
cbacbc

Source

Educational Codeforces Round 9
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