Boxes and Balls UVALive
来源:互联网 发布:网络支付有哪些 编辑:程序博客网 时间:2024/06/06 03:43
原因:
自身:
1.自己并没有考虑过精度所带来的问题。
2.一定要自己读题,独立思考,末被队友带偏(矛盾出真理)。
3.加强自身基础,提高自身实力。
队伍:
1.队友缺乏独立思考,需要加强。
题目描述:
给你n个球,求在有限次数变化中,球的变化最后稳定在一种状态。
思路:
打表找过规律后发现,稳定状态下球的个数是1,2,3,6,10,15,21.....是以等差数列的前n项和。s=(n+1)*n/2;
思路一:二分模拟(想到了,但是深度不够),没有尝试。
思路二:借二元一次方程。(x+1)*x-2n=0 可以求得x是一整一负的,取整,对于整数取齐下限xx,ans=(xx*xx+xx)/2(但是wa了,double 类的精度问题加一个判断语句即可(测试了后台数据近100组,都对,但就是wa了...比完之后才知道是精度问题,(思维的深度不够,,,))。具体看代码<_^_>....)
wa:
#include<bits/stdc++.h>using namespace std;typedef long long ll;int main (){ int t; scanf("%d",&t); ll n; int cnt=1; while (t--) { scanf("%lld",&n); ll ans ; double x=(sqrt(8*n+1)-1)/2; ll xx=ll(x); ans=(xx*xx+xx)/2; printf("Case #%d: %lld",cnt++,ans); cout<<endl; } return 0;}
ac:
#include <bits/stdc++.h>using namespace std;typedef unsigned long long ll;int main (){ ll t; cin>>t; ll cnt =1; while (t--) { ll n; cin>>n; ll ans; ll x=(sqrt(8*n+1)-1)/2; ans=x*x+x; ans/=2; if(ans>n) { ans=x*x-x; ans/=2; } cout<<"Case #"<<cnt++<<": "<<ans<<endl; } return 0;}
ac_two:(其他人的做法:貌似还是精度的问题)
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; int main () { ll t; cin>>t; ll cnt =1; while (t--) { ll n; cin>>n; ll ans; ll x=(sqrt((long double)8*n+1)-1)/2; ans=x*x+x; ans/=2; //if(ans>n) //{ // ans=x*x-x; // ans/=2; // } cout<<"Case #"<<cnt++<<": "<<ans<<endl; } return 0; }
阅读全文
1 0
- Boxes and Balls UVALive
- Boxes and Balls UVALive
- UVALive 7500 Boxes and Balls
- UVALive-7500-Boxes and Balls
- UVALive 7500 Boxes and Balls (二分)
- UVALive 7500 Boxes and Balls(模拟,二分)
- Balls and Boxes
- Boxes and Balls
- HDU5810 Balls and Boxes
- HDU5810-Balls and Boxes
- Balls and Boxes CodeForces
- Boxes And Balls CodeForces
- HDU 5810 Balls and Boxes
- 【HDU5810】Balls and Boxes(数学题)
- hdu 5810 Balls and Boxes
- hdu 5810 Balls and Boxes (数学)
- hdu5810 Balls and Boxes(数学)
- HDU 5810 Balls and Boxes(概率)
- Class类深入理解
- 这里有十个优质技术公众号,你都关注了吗?
- NLP入门+实战必读:一文教会你最常见的10种自然语言处理技术(附代码)
- cnn+rnn+attention
- 加速动态磁共振重建的低秩系数分解模型
- Boxes and Balls UVALive
- list
- opencv识别直线并显示文本
- 超励志!这位90后盲人程序员首创奥运历史
- 老玩家才懂的过往,Android系统消失不见的经典设计
- 在 Python 中实现单例模式
- 如何从一双腿判断男人行不行?
- 让不懂编程的人爱上iPhone开发(2017秋iOS11+Swift4+Xcode9版)-第1篇
- 01:谁考了第k名