codeforces 670B Game of Robots
来源:互联网 发布:鸿运抽奖软件注册码 编辑:程序博客网 时间:2024/06/16 11:25
题目意思是由题目给出的数列按照等差数列的方式算出一个新的数列,然后给出一个位置k,问在k位的数是多少。
等差数列求和运用,从头开始,一直求和,直到大于等于k就可以判断位置了。
#include <bits/stdc++.h>using namespace std;typedef __int64 ll;ll m, n;const int MAX = 1e6 + 5;ll arr[MAX];void file(){ freopen("C:\\Users\\MrZis\\Desktop\\input.txt", "r", stdin); freopen("C:\\Users\\MrZis\\Desktop\\output.txt", "w", stdout); return ;}int main(){ //file(); //read(); //solve(); //print(); scanf("%I64d%I64d", &n, &m); for (int i = 1; i <= n; ++i) { scanf("%d", &arr[i]); } ll sum = n * (1 + n) / 2; int res1 = 0; int res2 = -1; //cout << m << endl; for (int i = 1; i <= n; i++) { //cout << i * (1 + i) / 2 << endl; if ((ll)i * (1 + i) / 2 > m) { res1 = i; break; } else if ((ll)i * (1 + i) / 2 == m) { cout << arr[i] << endl; return 0; } } //cout << res1 << endl; //if (res2 != -1) // printf("%d\n", arr[res2]); //else if (res1 != 0) cout << arr[(ll)m - res1 * (res1 - 1) / 2] << endl; return 0;}
0 0
- codeforces 670B Game of Robots
- codeforces 670B Game of Robots
- CodeForces 670B Game of Robots
- CodeForces - 670B Game of Robots (模拟)水
- B - Game of Robots
- B. Game of Robots
- CodeForces 670B Game of Robots(第k个出现的数字)
- Codeforce Round#350(Div. 2) 670B Game of Robots
- codeforcs 350 B. Game of Robots
- Codeforces Round #350 (Div. 2) - B. Game of Robots (STL)
- Codeforces Round #350 (Div. 2) B. Game of Robots __ interesting
- Game of Robots
- 【codeforces 777B】Game of Credit Cards
- Codeforces 777B-Game of Credit Cards
- codeforces 777b Game of Credit Cards
- codeforces 839 B Game of the Rows
- Codeforces 839B-Game of the Rows
- Game of Credit Cards (Codeforces-777B)
- Java类的加载过程
- ubuntu 12.04/14.04 密码破解
- Intent和Intent Filter的区别
- C++作业5
- KEIL 在编译的时候优化设置问题
- codeforces 670B Game of Robots
- iOS开发系列--通知与消息机制
- 我使用的Xcode 常用插件
- leetcode.274. H-Index
- React中es6语法解析
- C++第四次实验——派生和继承1
- 设计模式工厂方法(FactoryMethod)
- More Effective C++----(17)考虑使用lazy evaluation(懒惰计算法)
- 121. Best Time to Buy and Sell Stock