Codeforces Round #539 (Div. 2) 题解
Codeforces Round #539 (Div. 2)
题目链接:https://codeforces.com/contest/1113
A. Sasha and His Trip
题意:
n个城市,城市分布在一条直线上且按升序排序,现在有个人开车从一号城市出发,车的油箱容量为v。
在每个城市都可以买油,但价格不一样:第i个城市买1单位的油花费i元。问最终从1到n花费的最少为多少。
题解:
贪心即可,尽量在前面的城市买油,最后一鼓作气到n号城市。
代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+;
int n,v;
int main(){
cin>>n>>v;
int fir=,las=n-v;
int ans=v;
if(n-<=v){
cout<<n-;
return ;
}
for(int i=;i<=las;i++){
ans+=i;
}
cout<<ans;
return ;
}
B. Sasha and Magnetic Machines
题意:
给出n个数,现在选定i,j,然后取x满足aj%x==0,之后让aj=aj/x,ai=ai*x。这个操作最多一次,问最后所有数的和最小为多少。
题解:
由于这里ai<=100,并且n也最多1e4,所以可以直接考虑暴力。但这里暴力的是,取到一个x的时候,应该始终就是让最小的那个ai来乘x,这应该是显而易见的。
具体见代码吧:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+;
int a[N];
int n;
int main(){
scanf("%d",&n);
int sum = ;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
sum+=a[i];
}
int ans = sum;
int mn = *min_element(a+,a+n+);
sum-=mn;
for(int i=;i<=n;i++){
for(int j=;j<=a[i];j++){
if(a[i]%j!=) continue ;
ans=min(ans,sum-a[i]+a[i]/j+mn*j);
}
}
cout<<ans;
return ;
}
C. Sasha and a Bit of Relax
题意:
给出n个数,然后让你找出满足条件的区间个数:区间长度为偶数且区间左部分的异或和等于右部分的异或和。
题解:
根据题中条件可以知道,那整个区间的异或和是为0的,然后根据异或前缀和进一步可知:假设那个区间为[l,r],那么prel-1=prer,这里prei为1~i的异或前缀和。并且还可以观察到,这里的l-1以及r是同奇偶的。
然后做法也大致清晰了,找出在奇偶位置异或前缀和为x的个数,假设我们目前只看奇数位置,有n个,那么这时对答案的贡献为C(n,2),也即是n*(n-1)/2;偶数也同样。
只是需要注意的是,当前缀异或和为0并且当前为偶数位置时,这也算一种情况。
具体代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int cnt[][<<];
int main(){
int n;
cin>>n;
vector <ll> a(n+);
for(int i=;i<=n;i++) scanf("%I64d",&a[i]);
ll sum=,ans=;
cnt[][]=;
for(int i=;i<=n;i++){
sum^=a[i];
ans+=cnt[i%][sum];
cnt[i%][sum]++;
}
cout<<ans;
return ;
}
D. Sasha and One More Name
题意:
给出一个回文串,然后让你用最少的次数分割为几个部分,之后可以拼接出一个和原来不同的回文串。如果不能就输出"Impossible",否则输出最少次数。
题解:
不能的情况很好判断。
在判断可行性过后,可以证明次数最多只需要两次,考虑从两边同时往中间走的切法就行了。
也就是说,我们只需要判断只切一次是否可行。由于字符串的长度只有5000,O(n^2)暴力即可。
代码如下:
#include <bits/stdc++.h>
using namespace std;
const int N = ;
string s;
int l;
bool is(string ss){
int f=;
for(int i=;i<l;i++){
int j=l-i-;
if(ss[i]!=ss[j]) f=;
}
return f&&ss!=s;
}
int main(){
cin>>s;
l=s.length();
int f=;
for(int i=;i<l;i++){
if(l& && i==l/) continue ;
if(s[i]!=s[]) f=;
}
if(f){
puts("Impossible");
return ;
}
f=;
for(int i=;i<l;i++){
string t1=s.substr(,i),t2=s.substr(i,l);
t2+=t1;
if(is(t2))f=;
}
if(f) cout<<<<endl;
else cout<<<<endl;
return ;
}
Codeforces Round #539 (Div. 2) 题解的更多相关文章
- Codeforces Round #539 (Div. 2) - D. Sasha and One More Name(思维)
Problem Codeforces Round #539 (Div. 2) - D. Sasha and One More Name Time Limit: 1000 mSec Problem ...
- Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax(思维题)
Problem Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax Time Limit: 2000 mSec Problem ...
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
- Codeforces Round #539 (Div. 2)
Codeforces Round #539 (Div. 2) A - Sasha and His Trip #include<bits/stdc++.h> #include<iost ...
- Codeforces Round #608 (Div. 2) 题解
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
- Codeforces Round #525 (Div. 2)题解
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
- Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
随机推荐
- html简约风用户登录界面网页制作html5-css-jquary-学习模版
2018--12-12 喜迎双十二,咳咳,,,,我不是打广告哈,购物的节日也不要忘记学习. 大家好,我又来了. 今天抽出来空把自己的学习心得给大家分享,这是一个可开发可扩展的用户登录界面,用于开发学习 ...
- 如何借助windows的VHD引导特性实现VHD多windows系统共存
近期,由于一些需要,需要运行3个windows系统,具体需要如何此处略去,现将实现方式共享如下. 测试环境: HP 820 G2, 4G内存, 500G SSD硬盘 windows 7 企业版 win ...
- CVPR2018 关于视频目标跟踪(Object Tracking)的论文简要分析与总结
本文转自:https://blog.csdn.net/weixin_40645129/article/details/81173088 CVPR2018已公布关于视频目标跟踪的论文简要分析与总结 一, ...
- spring boot 下使用@ConponentScan注解遇到的问题
问题描述 如果你心急看结果,请直接到本文末尾 今天使用了注解操作spring boot,一开始程序无法启动,提示无法找到一个注解注入的类,查询网上,有人说使用@ConponetScan注解,可以指定需 ...
- 概要梳理kafka知识点
主要是梳理一下kafka学习中的一些注意点,按照消息的流动方向进行梳理.详细的kafka介绍推荐看骑着龙的羊的系列博客,具体的某一块的知识点,可以参考我给出的一些参考文章. 1. kafka在系统中的 ...
- LeetCode - 268. Missing Number - stable_sort应用实例 - ( C++ ) - 解题报告
1.题目大意 Given an array nums, write a function to move all 0's to the end of it while maintaining the ...
- Python3 Tkinter-Button
1.绑定事件处理函数 from tkinter import * def hello(): print('Hello!') root=Tk() button=Button(root,text='cli ...
- MongoDB Sharding 机制分析
MongoDB Sharding 机制分析 MongoDB 是一种流行的非关系型数据库.作为一种文档型数据库,除了有无 schema 的灵活的数据结构,支持复杂.丰富的查询功能外,MongoDB 还自 ...
- 各类4G手机进入工参模式查看手机信息
随着移动4G正式商用,LTE网络建设日益完善,LTE用户日趋增多,通过进入其工程模式读取服务小区电平RSRP.物理小区标识PCI和频点号等基本信息的方式来判断测试点信号质量的优劣.由于市场上商用终端品 ...
- Fluent Python: Mutable Types as Parameter Defaults: Bad Idea
在Fluent Python一书第八章有一个示例,未看书以先很难理解这个示例运行的结果,我们先看结果,然后再分析问题原因: 定义了如下Bus类: class Bus: def __init__(sel ...