round

Round 1203 (Codeforces Round #579(div.3))题解

只谈情不闲聊 提交于 2019-11-27 07:09:58
Problem A 题意 有一个长度为 \(n\) 的数组 \(a\) ,是 \(1\) ~ \(n\) 的一个排列。问这个排列满不满足 \[a_k=1,a_i+1=a_{i+1}(1 \leq i \leq k-2),a_j+1=a_{j+1}(k \leq j \leq n-1)\] 或 \[a_k=1,a_i-1={a_i+1}(1\leq i \leq k-1),a_j-1=a_{j+1}(k+1\leq j \leq n-1)\] 。 来源: https://www.cnblogs.com/liuzongxin/p/11349973.html

Python总结:保留小数点任意位round函数不够精确

不羁的心 提交于 2019-11-26 14:10:56
QUESTION:Python总结:保留小数点任意位round函数不够精确 ANWSER: 目录 QUESTION:Python总结:保留小数点任意位round函数不够精确 ANWSER: 一:使用round函数保留小数位数 二:使用print("%.nf"%N) 三:使用print(format(N,".nf")) 一:使用round函数保留小数位数 该方法并不严格有效,当X小数位数n<N时,仅能够输出n位小数。​​​​​​​ 二:使用print("%.nf"%N) 三:使用print(format(N,".nf")) print(round(2,2)) #2 print(round(2.0,2)) #2.0 print(round(2.00,2)) #2.0 print('%.2f'%10) #10.00 print(format(10,'.2f')) #10.00 注意: round不是简单的四舍五入 round()如果只有一个数作为参数,不指定位数的时候,返回的是一个整数,而且是最靠近的整数(这点上类似四舍五入)。但是当出现.5的时候,两边的距离都一样,round()取靠近的偶数,这就是为什么round(2.5) = 2。当指定取舍的小数点位数的时候,一般情况也是使用四舍五入的规则,但是碰到.5的这样情况,如果要取舍的位数前的小树是奇数,则直接舍弃,如果偶数这向上取舍。

Math的round方法

痞子三分冷 提交于 2019-11-26 12:32:22
代码如下,后面的注释是输出的结果 public static void main(String[] args) { System.out.println(Math.round(0.399));//0 System.out.println(Math.round(0.4));//0 System.out.println(Math.round(0.41));//0 System.out.println(Math.round(0.499));//0 System.out.println(Math.round(0.5));//1 System.out.println(Math.round(0.51));//1 System.out.println(Math.round(0.6));//1 System.out.println("======================"); System.out.println(Math.round(-0.6));//-1 System.out.println(Math.round(-0.51));//-1 System.out.println(Math.round(-0.5));//0 System.out.println(Math.round(-0.499));//0 System.out.println(Math.round(-0.41));//0

Codeforces Round #601 (Div. 2) B Fridge Lockers

情到浓时终转凉″ 提交于 2019-11-26 00:47:47
//题目要求的是每一个点最少要有两条边连接,所以可以先构成一个环。然后再把剩余的最短的边连接起来 #include<iostream> #include<algorithm> using namespace std ; const int N=100010; int n,m; struct edge { int num; int w; } a[N]; int T; bool cmp(edge a,edge b) { return a.w<b.w; } void solve() { int ans=0; for(int i=1; i<=n; i++) { ans+=2*a[i].w; } ans+=(m-n)*(a[1].w+a[2].w); cout<<ans<<endl; for(int i=1; i<n; i++) cout<<i<<" "<<i+1<<endl; cout<<n<<" "<<"1"<<endl; for(int i=1; i<=m-n; i++) cout<<a[1].num<<" "<<a[2].num<<endl; } int main() { cin>>T; while(T--) { cin>>n>>m; for(int i=1; i<=n; i++) { cin>>a[i].w; a[i].num=i; } if(n<=2||m<n) { cout<<