CodeForces 670B、HDU 1003、CodeForces 632C
来源:互联网 发布:通州淘宝城在哪个位置 编辑:程序博客网 时间:2024/06/01 09:47
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 000, 1 ≤ 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
2 21 2
1
4 510 4 18 3
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;}
Description
Input
Output
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数组,记录到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;}
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
4abbaabacababcder
abacabaabbabcder
5xxxxxaxxaaxxaaa
xxaaaxxaaxxaxxx
3ccbcba
cbacbc
Source
#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;}
一天做一道题就好,反正现在也没那么功利了,完全靠兴趣。
真正要功利的是应试考研,方法总是有的,但要真的努力与动力。
有时候无论作什么都没那么多理由,但你心中总要有一个信念,而不要掺杂太多思想。
那就是成为大人物的渴望,不再那么渺小吧。梦想有一天真正成为自己想成为的那个人,现在就是不懈地区努力。
未来是什么样真的不知道,但毕竟充满危险压力与残酷,武装好自己,做好自己才是真正现在应该做的事。
- CodeForces 670B、HDU 1003、CodeForces 632C
- CodeForces 570B,C
- codeforces 282 A B C
- Codeforces 300-A/B/C
- codeforces 124B、124C
- CodeForces 560A,B,C
- CodeForces 572A,B,C
- CodeForces 707-A,B,C
- Codeforces 371 A,B,C
- codeforces-757-【B、C思维】
- codeforces-758【B、C思维】
- codeforces 791B 791 C
- codeforces 883C. Downloading B++
- CodeForces 632B
- Codeforces 632B
- codeforces B
- codeforces B
- codeforces B
- Android中adapter调用notifyDataSetChanged无效原因总结
- Does Java pass by reference or pass by value?
- Java 加密解密之对称加密算法DESede
- Levmar 配置
- UGUI实现操纵摇杆
- CodeForces 670B、HDU 1003、CodeForces 632C
- Trouble Shoot - The prefix "context" for element "context:component-scan" is not bound. Spring MVC
- HDU 2896 病毒侵袭
- LinearLayout及其常用属性
- javascript框架思想1
- Java 加密解密之对称加密算法AES
- (6)函数
- bzoj3198【SDOI2013】spring
- KMP算法