栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 软件开发 > 后端开发 > Python

Codeforces Round #812 (Div. 2)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Codeforces Round #812 (Div. 2)

A.
import math
import os
import collections
import sys

T = int(input())
for _ in range(T):
    n=int(input())
    ux=0
    dx=0
    uy=0
    dy=0
    for i in range(n):
        x,y=map(int,input().split())
        ux=max(ux,x)
        uy=max(uy,y)
        dx=min(dx,x)
        dy=min(dy,y)
    ans=(ux-dx)+(uy-dy)
    ans*=2
    print(ans)

B
import math
import os
import collections
import sys

T = int(input())
for _ in range(T):
    n=int(input())
    a=list(map(int,input().split()))
    f=0
    pre=[-1]*n
    suf=[-1]*n
    for i in range(1,n):
        pre[i]=max(pre[i-1],a[i-1])
    for i in range(n-2,-1,-1):
        suf[i]=max(suf[i+1],a[i+1])
    '''for i in range(1,n-1):
        print(str(i)+" "+str(pre[i])+" "+str(suf[i]))'''
    for i in range(1,n-1):
        if a[i] 
C 

这个主要是在[x,2x]之间一定存在一个平方数
比如 0,1,2,3,4,5,6,7,8,9,10
找0-5的一个排列
首先5-10中一定有一个平方数,选择9;5+4=9,4+5=9,因此4,5都被用完了,然后可用的数就是0-3
再来看>=3的平方数是4,3+1=4,2+2=4,1+3=4;因此,1-3被用完了;
然后剩一个0,0+0也是平方数
python的ceil之前没用过

import math
import os
import collections
import sys

T = int(input())
for _ in range(T):
    n=int(input())
    res=[0]*n
    l,r=n-1,n-1
    while l>=0:
        t= math.ceil(r ** .5) ** 2
        l=t-r
        for i in range(l,r+1):
            res[i]=t-i
        l-=1
        r=l
    print(*res)


转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/1037690.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号