Codeforces_820
A.直接模拟。
#include<bits/stdc++.h>
using namespace std; int c,v0,v1,a,l; int main()
{
ios::sync_with_stdio();
cin >> c >> v0 >> v1 >> a >> l;
int ans = ,now = l,v = v0-a;
while()
{
ans++;
now -= l;
v += a;
if(v > v1) v = v1;
now += v;
if(now >= c) break;
}
cout << ans << endl;
return ;
}
B.相等弧长对应的圆周角相等。圆周角是对应圆心角的一半。
#include<bits/stdc++.h>
using namespace std; int n,a; int main()
{
ios::sync_with_stdio();
cin >> n >> a;
double t = 180.0/n;
int ans;
double minn = ;
for(int i = ;i <= n-;i++)
{
if(abs(i*t-a) < minn)
{
ans = i+;
minn = abs(i*t-a);
}
}
cout << "2 1 " << ans << endl;
return ;
}
D.统计数值大于等于位置的个数和数值小于位置的个数,以及每个偏差值的个数,每次向右移动的时候,可以O(1)更新答案,注意每次更新三个计数。
#include<bits/stdc++.h>
using namespace std; int n,a[],cnt[]; int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i];
long long sum = ,cntl = ,cntr = ;
for(int i = ;i <= n;i++)
{
sum += abs(a[i]-i);
if(a[i] >= i)
{
cntl++;
cnt[a[i]-i]++;
}
else cntr++;
}
long long ans = sum;
int num = ;
for(int i = ;i < n;i++)
{
cntl -= cnt[i-];
cntr += cnt[i-];
sum = sum-cntl+cntr-abs(a[n-i+]-n-)+abs(a[n-i+]-);
if(a[n-i+]+i- < n) cnt[a[n-i+]+i-]++;
cntl++;
cntr--;
if(sum < ans)
{
ans = sum;
num = i;
}
}
cout << ans << " " << num << endl;
return ;
}
Codeforces_820的更多相关文章
随机推荐
- 01_垂直居中body中的应用
1: 应用场景 在body中书写一个代码块, 使其相对于body垂直居中 <!DOCTYPE html> <html lang="en"> <head ...
- Django之表高级操作
目录 一.如何开启自己的测试脚本? 二.对表数据的添加.更新.删除 1.create() 2.update() 3.delete() 4.查看执行的sql语句 三. 单表查询13个操作 返回Query ...
- Angular.的简单运用
从script引用angular文件.开始编写angular事件: 在angular文件中添加属性: ag-xxxx;初始化使用: ng-app="name"; 没有这个属性就不会 ...
- 测开大佬告诉你:如何5分钟快速创建restful风格的API接口-使用django restframework框架
一.思考❓❔ 1.创建API接口难吗? 软件测试工程师: 只测过API接口, 从没创建过 应该需要掌握一门后端开发语言和后端开发框架吧!? 脑容量有限,想想就可怕 2.如何创建API接口呢? 使用Dj ...
- Java ArrayList类的简单介绍
ArrayList类的说明: ArrayList类是List接口的实现类,java.util.ArrayList集合数据存储的结构是数组结构. 特点: 元素增删慢,查找快.(由于日常开发中使用最多的功 ...
- P4513 小白逛公园 动态维护最大子段和
题目链接:https://www.luogu.org/problem/P4513 #include<iostream> #include<cstdio> #include< ...
- Win10永久版低价购买及激活工具使用说明
目录 按 发展历程 用户界面 激活工具 按 Windows 10是由美国微软公司开发的应用于计算机和平板电脑的操作系统,于2015年7月29日发布正式版. Windows 10操作系统在易用性和安全性 ...
- IDEA 公司推出新字体,极度舒适~
这几天炒得沸沸扬扬的 Intellij IDEA 公司 JetBrains 推出了一种新字体:JetBrains Mono,据说它是专为开发人员设计的,下面栈长带大家一起来吃个瓜. JetBrains ...
- Java.Json模板.省市区三级JSON
[ { "name": "北京市", "city": [ { "name": "北京市", &quo ...
- C++中虚析构的作用
为了当用一个基类的指针删除一个派生类的对象时,派生类的析构函数会被调用. 基本概念: 析构函数是用来回收对象的: 虚析构函数是析构函数的一种: 基类是一类对象共有属性的抽象.比如,猫和狗都是动物,都会 ...