Codeforces_820
2024-09-01 03:52:07
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 ;
}
最新文章
- Bugtags 2016-10-17 更新内容
- 8、需求分析师要阅读的书籍 - IT软件人员书籍系列文章
- 【软件工程实践一】git使用心得
- A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list.
- 第三百五十一天 how can I 坚持
- 常用mysql命令大全
- struts中的helloword(1)
- SQLite的SQL语法
- Android-x86 4.4-r5 发布,PC 上的安卓系统
- Sipdroid实现SIP(三): 消息接收处理
- 转载:数位DP模板
- 老帖收藏,留供参考:SpringMvc2.5+Mybatis3.2.7
- Linux 文件/文件夹无法删除问题解决方案
- Fiddler-抓取手机app请求
- 20165220 mybash
- awk、sed、date命令使用
- Kotlin 对象表达式和对象声明
- IntelliJ IDEA mybatis-generator的使用
- |ERROR|ERROR: missing data for column ";createtime"; (seg3 slice1 192.168.66.23:40001 pid=33370)之mysql换行符或者空格引起的问题
- maven 学习