7.26-Codeforces Round #372 (Div. 2)
C. Plus and Square Root
链接:codeforces.com/group/1EzrFFyOc0/contest/716/problem/C
题型:构造
题意:起始数 x 为 2,在当前位置 i 可重复加上 i,直到 x 为 (( i + 1 )* k )^ 2 ( k = 1,2,3,4...)则来到位置 i+1 ,问每一步要加上多少次 i
题解:做的时候找到规律和构造式一样...但是因为爆ll没过。看了正派题解(https://blog.csdn.net/cmershen/article/details/52624592)
自己再梳理一下:
在即将跳到下一个 level 的时刻,x 要满足以下条件
① x 为 i 的倍数 ,无论是加上 k 个 i 之前还是之后
② x 为 ( i + 1 ) 的倍数
③ x 为完全平方数
则设 x = i ^ 2 * ( i + 1 ) ^ 2 ,由于递推,在刚抵达 i 时 x ' = i *( i - 1 ),所以 ans = ( x - x ' ) / i = i * i * i + 2 * i * i + 1 , 又 i = 1 时 起始值为 2 而非 i *( i - 1 ),所以要特判。
其他的满足条件的构造式都符合,解不唯一。
原因:迭代器设为int后爆ll,四次方爆ll,请记住。
代码:
/*找规律迭代器设为int后爆ll,四次方爆ll*/ #include <iostream> #include <string.h> #include <algorithm> #include <stdio.h> #include <string> #include <map> #include <vector> #include <cmath> #include <set> #define ll long long #define PI 3.1415926535 using namespace std; const int inf=2e5+10; //map<int,int> s; bool cmp(const string& a,const string& b) {return a.length()<b.length(); } map<char,int>mp; int main() {ll n;cin>>n;ll t=2;for(ll i=1;i<=n;i++){ll temp;temp=i*(i+1);ll ans;//ans=(temp*temp-t)/i;ans=temp/i*temp-t/i;t=temp;cout<<ans<<endl;} }
/*构造,即规律的展开式*/ #include <iostream> #include <string.h> #include <algorithm> #include <stdio.h> #include <string> #include <map> #include <vector> #include <cmath> #include <set> #define ll long long #define PI 3.1415926535 using namespace std; const int inf=2e5+10; //map<int,int> s; bool cmp(const string& a,const string& b) {return a.length()<b.length(); } map<char,int>mp; int main() {ll n;cin>>n;ll t=2;cout<<2<<endl;for(ll i=2;i<=n;i++){//ll temp;//temp=i*(i+1); ll ans;//ans=(temp*temp-t)/i;//ans=temp/i*temp-t/i;ans=i*i*i+2*i*i+1;//t=temp;cout<<ans<<endl;}}
转载于:https://www.cnblogs.com/LLbinGG/p/9370977.html
7.26-Codeforces Round #372 (Div. 2)相关推荐
- Codeforces Round #372 (Div. 2), problem: (B) Complete the Word
水题,每次截取长度为26的字符串,然后直接进行修改就可以 然而本弱渣昨天wa看很久 include<bits/stdc++.h> using namespace std; int n,c; ...
- Codeforces Round #372 (Div. 1) B. Complete The Graph
题目链接:传送门 题目大意:给你一副无向图,边有权值,初始权值>=0,若权值==0,则需要把它变为一个正整数(不超过1e18),现在问你有没有一种方法, 使图中的边权值都变为正整数的时候,从 S ...
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...
- DFS Codeforces Round #299 (Div. 2) B. Tavas and SaDDas
题目传送门 1 /* 2 DFS:按照长度来DFS,最后排序 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #includ ...
- 组合数学题 Codeforces Round #108 (Div. 2) C. Pocket Book
题目传送门 1 /* 2 题意:每一次任选i,j行字符串进行任意长度前缀交换,然后不断重复这个过程,问在过程中,第一行字符串不同的个数 3 组合数学题:每一列不同的字母都有可能到第一行,所以每列的可能 ...
- 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns
题目传送门 1 /* 2 题意:删除若干行,使得n行字符串成递增排序 3 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 4 */ 5 /************* ...
- Codeforces Round 263(Div. 2)
layout: post title: Codeforces Round 263(Div. 2) author: "luowentaoaa" catalog: true tags: ...
- 贪心 Codeforces Round #236 (Div. 2) A. Nuts
题目传送门 1 /* 2 贪心:每一次选取最多的线段,最大能放置nuts,直到放完为止,很贪婪! 3 题目读不懂多读几遍:) 4 */ 5 #include <cstdio> 6 #inc ...
- 贪心 Codeforces Round #191 (Div. 2) A. Flipping Game
题目传送门 1 /* 2 贪心:暴力贪心水水 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cs ...
- 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram
题目地址:http://codeforces.com/contest/435/problem/C 1 /* 2 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 3 模拟题:蛮恶心的 ...
最新文章
- 深入理解PHP之OpCode
- 学习HTML-Beautify.js
- 我们处理了10亿个Java记录的错误-这是导致97%的错误的原因
- MyEclipse的Debug模式
- java发送请求_Java发送Http请求
- orb特征 稠密特征_特征点的基本概念和如何找到它们
- 好想找一个灵魂伴侣,然后带着他一起周游世界,会实现吗?
- n!的分解 soj 2666
- RK3288_Android7.1调试uart串口屏
- Android学习——四大核心组件(核心知识点整理)
- python身份证号码计算年龄
- 800元以内创建的双路CPU主机
- Epub 转 txt
- MySQL每天定时12点弹出黑窗口
- 数据中心机房建设中的关键问题都有哪些?
- SingleShot姿态估计部署教程
- 【数据结构】图(最短路径Dijkstra算法)的JAVA代码实现
- 2022出海拉美:巴西电商市场现状及网红营销特点
- 像角斗士一样地活着!
- web编程(三)显示html网页