Codeforces Round #638 div2 A(等比数列的性质,循环求解)
A. Phoenix and Balance
题意:
要你把一个等比数列,平均分成两堆,要求和的差值最小
思路:
- 等比数列的一个性质:a【i】>sum【i-1】(第i项大于前i-1项的和)
- 所以a【1】+a【2】+a【3】+……+a【n】,
有a【n】>a【1】+a【2】+……+a【n-1】;
而要最小那么就a【n】+a【1】+a【2】+a【3】+……+a【n/2-1】(使大的那一堆尽可能的小)
反思:
- 多用编程的思维,eg循环使用
AC
#include <iostream>
#include <cstdio>
#include <cmath>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
typedef long long ll;
int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;cin>>t;while(t--){int n;cin>>n;ll ans=0;For(i,1,n){if(i==n||i<n/2)ans+=(ll)1<<i;else ans-=(ll)1<<i;}cout<<ans<<'\n';}return 0;
}
Codeforces Round #638 div2 A(等比数列的性质,循环求解)相关推荐
- codeforces Round#429 (Div2)
2017-08-20 10:00:37 writer:pprp 用头文件#include <bits/stdc++.h>很方便 A. Generous Kefa codeforces 84 ...
- Codeforces Round#310 div2
C题:这题说的是套娃,如果做题的时候知道是套娃,那就好理解多了 规则1:套娃A可以放到套娃B里面,当且仅当套娃B没有放在其他套娃里面 规则2:套娃A放在套娃B里面,且套娃B没有放在其他套娃里面,那么可 ...
- Codeforces Round #359 div2
Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...
- Codeforces Round 361 div2
雪崩,全错掉了GG.前两道题相对之前的难度大一点啊,不过A题有个循环应该是从0开始而不是1开始这样的低级错误不应该犯.B题差不多是一个BFS,但是我当时始终绕着最短路径写来写去,一直各种TLE与WA. ...
- Codeforces Round #360(div2)
考完试的晚上,打了场codeforces,主要感觉由于睡眠不够,最后差了点劲啊,C题基本上都过了,但忙中出错最后把数组调小易于debug后再提交又忘记改回来了,看到Runtime Error自己竟没反 ...
- codeforces round 416 div2补题
第一题,水题 A. Vladik and Courtes #include<bits/stdc++.h> using namespace std; int main() {long lon ...
- codeforces round 421 div2 补题 CF 820 A-E
A Mister B and Book Reading O(n)暴力即可 #include<bits/stdc++.h> using namespace std; typedef lon ...
- codeforces round #576 div2 D Welfare State(线段树)[单点修改+区间修改]
题意:有一些数字,以及一些操作.操作一是单点修改,输入1 b c,将位置b改成c,操作二是输入2 a,将不大于a的数全部改成a.求更改完毕后的数. tag的运用:tag是对被覆盖区间上加一个标记,那么 ...
- codeforces round 418 div2 补题 CF 814 A-E
A An abandoned sentiment from past 水题 #include<bits/stdc++.h>using namespace std;int a[300],b[ ...
最新文章
- 微软语音AI技术与微软听听文档小程序实践 | AI ProCon 2019
- db2 某个字段排序_db2 中文排序 按拼音排序(utf-8编码)
- 咏南LINUX中间件
- Actions require unique method/path combination for Swagger
- python应用程序类型_python – 类型提示条件可变参数应用程序
- mysql数据库建立的数据库在哪个文件夹?
- 指定Gradle构建属性
- Jeecg-Uniapp 移动框架开发环境搭建—— APP解决方案
- Tween Animation----Translate位置移动动画
- 添加git 忽略文件
- TypeScript笔记(3)—— 使用WebPack工具
- java rcfile,hsqldb sqltool rcfile不起作用
- linux wireless子系统,Linux Wireless子系统初始化
- 修改Layui表单验证提示框样式
- json转map几种方法
- win10系统 DNS服务器,dns出错?Win10系统dns服务器未响应的修复方法
- opc 接口计算机,OPC接口使用技巧
- java tea collection_Javaの集合学习
- 关于软件产品化的几点思考【转】
- 大华linux密码,Linux用户和组的实战练习