Codeforces Round 920 (Div. 3)(A~F)
A
按题意模拟即可
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve()
{
set<pii>s;
rep(i,1,4){
int x,y;cin>>x>>y;
s.insert({x,y});
}
for(auto [x1,y1]:s){
for(auto [x2,y2]:s){
if(x1==x2&&y1==y2) continue;
if(x1==x2){
cout<<abs(y1-y2)*abs(y1-y2)<<endl;
return;
}
}
}
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
B
统计01和10的数量取最大值
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve()
{
string s1,s2;
int n;cin>>n;
cin>>s1>>s2;
int cnt1=0,cnt2=0;
rep(i,0,s1.size()-1){
if(s1[i]=='0'&&s2[i]=='1') {
cnt1++;
}else if(s1[i]=='1'&&s2[i]=='0'){
cnt2++;
}
}
cout<<min(cnt1,cnt2)+abs(cnt1-cnt2)<<endl;
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
C
考虑贪心,到达当前如果a操作的代价大选择b操作,b操作的代价大选择a操作
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve()
{
int n,f,a,b;cin>>n>>f>>a>>b;
vector<int>t(n+1);
int ans=0;
rep(i,1,n){
cin>>t[i];
int costa=(t[i]-t[i-1])*a;
int costb=b;
ans+=min(costa,costb);
}
cout<<(ans>=f?"no":"yes")<<endl;
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
D
双指针+贪心
先将两个数组排序,a升序,b降序。
然后比较两个端点的对答案的贡献,选择贡献大的
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve()
{
int n,m;cin>>n>>m;
vector<int>a(n+1),b(m+1);
rep(i,1,n){
cin>>a[i];
}
rep(i,1,m){
cin>>b[i];
}
sort(a.begin()+1,a.begin()+1+n);
sort(b.begin()+1,b.begin()+1+m,greater<int>());
int ans=0,la=1,ra=n,lb=1,rb=m;
rep(i,1,n){
int dl=abs(a[la]-b[lb]),dr=abs(a[ra]-b[rb]);
if(dl>dr){
ans+=dl;
la++;lb++;
}else{
ans+=dr;
ra--;rb--;
}
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
E
博弈论的题目
将行列分开考虑
先考虑行,最终两者一定会走到一行。
什么情况下alice可能会赢,一定是\(yb-ya\)为奇数时
当\(yb-ya\)为偶数时,bob可能赢
然后考虑列一定是一方经过turn伦将对方挤到边界处获胜
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve()
{
int n,m;cin>>n>>m;
int xa,ya,xb,yb;cin>>ya>>xa>>yb>>xb;
int diff=yb-ya;
if(diff<=0){
cout<<"draw"<<endl;
return;
}
int turn=diff>>1;
if(diff&1){
if(xb>xa){
xa=min(xa+turn+1,m);
xb=min(xb+turn,m);
if(xa>=xb) cout<<"alice"<<endl;
else cout<<"draw"<<endl;
}else{
xa=max(xa-turn-1,1*1ll);
xb=max(xb-turn,1*1ll);
if(xa<=xb) cout<<"alice"<<endl;
else cout<<"draw"<<endl;
}
}else{
if(xa>xb){
xa=min(xa+turn,m);
xb=min(xb+turn,m);
if(xa<=xb) cout<<"bob"<<endl;
else cout<<"draw"<<endl;
}else{
xa=max(xa-turn,1*1ll);
xb=max(xb-turn,1*1ll);
if(xa>=xb) cout<<"bob"<<endl;
else cout<<"draw"<<endl;
}
}
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
F
根号分治
根号分治
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
int f[330][100010],g[330][100010];
void solve()
{
int n,q;cin>>n>>q;
vector<int>a(n+1);
rep(i,1,n){
cin>>a[i];
}
//预处理出来模数比较小的情况
int sq=sqrt(n);
rep(i,1,sq){
rep(j,1,n){
f[i][j]=(j-i>=0?f[i][j-i]:0)+j/i*a[j];
g[i][j]=(j-i>=0?g[i][j-i]:0)+a[j];
}
}
while(q--){
int s,d,k;cin>>s>>d>>k;
//模数较小直接查询预处理的结果
if(d<=sq){
int ans=0;
ans+=f[d][s+(k-1)*d]-(s-d>=0?f[d][s-d]:0);
ans-=(s/d-1)*(g[d][s+(k-1)*d]-(s-d>=0?g[d][s-d]:0));
cout<<ans<<' ';
}else{
//较大的话暴力去做
int ans=0;
for(int i=s,j=1;j<=k;i+=d,j++){
ans+=j*a[i];
}
cout<<ans<<' ';
}
}
cout<<endl;
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
Codeforces Round 920 (Div. 3)(A~F)的更多相关文章
- Codeforces Round #316 (Div. 2) (ABC题)
A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序) ...
- Codeforces Round #240 (Div. 2)(A -- D)
点我看题目 A. Mashmokh and Lights time limit per test:1 secondmemory limit per test:256 megabytesinput:st ...
- Codeforces Round #395 (Div. 2)(未完)
2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> ...
- Codeforces Round #324 (Div. 2) (哥德巴赫猜想)
题目:http://codeforces.com/problemset/problem/584/D 思路: 关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和. 关于奇数的哥德巴赫猜想:任一 ...
- B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)
---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integ ...
- 【Codeforces】Codeforces Round #491 (Div. 2) (Contest 991)
题目 传送门:QWQ A:A - If at first you don't succeed... 分析: 按照题意模拟 代码: #include <bits/stdc++.h> usin ...
- 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)
题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...
- Codeforces Round #671 (Div. 2) (A~E)
Link~ 题面差评,整场都在读题 A 根据奇偶性判断一下即可. #include<bits/stdc++.h> #define ll long long #define N #defin ...
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
随机推荐
- widows 安装docker
1.安装docker 依次安装如下两个文件: 如启动docker报错:可以是hv没有开启,按如下方法解决 (23条消息) Windows10启动Docker报错:Hardware assisted v ...
- python2排序
python list cmp排序 对于list的排序一般使用cmp 示例: sorted(xxlist, cmp=self.sortFunc) def sortFunc(self, a, b): r ...
- 手撕Vuex-添加全局$store
经过上一篇的介绍,了解到了 Vuex 的实现本质就是一个插件,所以要做的事情就是实现这个插件的代码编写即可. 本篇文章主要是实现一个全局的 $store,这个 $store 是挂载在 Vue 的原型上 ...
- 从github上下载代码到本地
相关链接: 码云(gitee)配置SSH密钥 码云gitee创建仓库并用git上传文件 git 上传错误This oplation equires one of the flowi vrsionsot ...
- 【7】python_matplotlib 输出(保存)矢量图方法;画图时图例说明(legend)放到图像外侧;Python_matplotlib图例放在外侧保存时显示不完整问题解决
1.python_matplotlib 输出(保存)矢量图方法 用python的matplotlib画出的图,一般是需要保存到本地使用的.如果是用show()展出的图,再右键保存,这样的图是失帧而非矢 ...
- Linux的用户和权限 [补档-2023-07-07]
Linux用户和权限 3-1. su用户切换命令 exit用户退出命令 用户切换命令的语法: su [-] [用户名] 其中: - 可选,表示是否在切换用户后加载环境变量,建议带上. ...
- Java-Stream-flatMap
Leave leave1 = new Leave("1","1",new Date(),CollUtil.newArrayList("A", ...
- 多进程|基于非阻塞调用的轮询检测方案|进程等待|重新理解挂起|Linux OS
说在前面 今天给大家带来操作系统中进程等待的概念,我们学习的操作系统是Linux操作系统. 我们今天主要的目标就是认识wait和waitpid这两个系统调用. 前言 那么这里博主先安利一下一些干货满满 ...
- 应用--WebApplication
应用--Program中的WebApplication 在6.0,微软团队对于NetCore做了很大的改变,其中有一个改变就是推出了新的托管模型--最小托管模型,使用该模型可以创建最小的web应用.( ...
- 24.3 向量化异常VEH--《Windows核心编程》
Windows 提供了向量化异常处理(vectored excepation handing,VEH)机制.程序可以注册一个函数,每当异常发送或者一个未处理异常脱离标准SEH的控制时,这个函数就会被调 ...