Educational Codeforces Round 7
来源:互联网 发布:ubuntu创建文件 编辑:程序博客网 时间:2024/06/13 02:04
Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).
Find the number on the n-th position of the sequence.
The only line contains integer n (1 ≤ n ≤ 1014) — the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Print the element in the n-th position of the sequence (the elements are numerated from one).
3
2
5
2
10
4
55
10
56
1
题意:给一串数字,找出规律,求第n个数是多少
解:找规律
<span style="font-size:14px;">#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;#define LL __int64int main(){ LL n; while(scanf("%I64d",&n)!=EOF) { LL m=floor((-1+sqrt(8*n-7))/2); LL x=n-m*(m+1)/2; printf("%I64d\n",x); } return 0;}</span>
水过吧
<span style="font-size:14px;">#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){ int h,m,a; while(scanf("%d:%d",&h,&m)!=EOF) { scanf("%d",&a); int M=(a+m)%60; int x=(a+m)/60; int H=(h+x)%24; printf("%02d:%02d\n",H,M); } return 0;}</span>
解:可以这样做,如果上一个元素和当前元素相同,表示成pre[i]=pre[i-1],不同就pre[i]=i-1;最后如果a[r]!=x输出r,否则的话就pre[r]>=l的话,就输出pre[r];如果不满足上诉情况,直接输出-1;
<span style="font-size:14px;">#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxm=2e5+10;int a[maxm];int pre[maxm];int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { memset(pre,0,sizeof(pre)); memset(a,0,sizeof(a)); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); if(a[i]!=a[i-1]) { pre[i]=i-1; } else { pre[i]=pre[i-1]; } } int l,r,x; for(int i=0;i<m;i++) { scanf("%d%d%d",&l,&r,&x); int id=-1; if(a[r]!=x) { id=r; } else if(pre[r]>=l) { id=pre[r]; } printf("%d\n",id); } } return 0;}</span>
- Educational Codeforces Round 7
- Educational Codeforces Round 7
- Educational Codeforces Round 7
- Educational Codeforces Round 7
- Educational Codeforces Round 7
- Educational Codeforces Round 7 题解
- Educational Codeforces Round 7 ABCDE
- Educational Codeforces Round 7总结
- Educational Codeforces Round 7 题解
- Educational Codeforces Round 7--A. Infinite Sequence
- Educational Codeforces Round 7--B. The Time
- Educational Codeforces Round 7 A. Infinite Sequence
- Educational Codeforces Round 7 B. The Time
- Educational Codeforces Round 7(A)数学
- Educational Codeforces Round 7(B)模拟
- Educational Codeforces Round 1
- Educational Codeforces Round 2
- Educational Codeforces Round 2
- linux下samba的安装
- 用PYTHON調用MATLAB的函數
- dll 文件加载
- 快速掌握Lua 5.3 —— 面向对象编程
- bzoj3670:NOI2014 动物园
- Educational Codeforces Round 7
- org.apache.hadoop.conf.Configuration.getFloat(String arg0, float arg1)
- hadoop源码解析—— conf包中Configuration.java解析(一)
- Android国际化
- hadoop源码解析—— conf包中Configuration.java解析(二)
- 1018. Public Bike Management (30)
- 1019. General Palindromic Number (20)
- 1020. Tree Traversals (25)
- shell程序设计(三)