Codeforces Round #539 (Div. 2)

题目链接:https://codeforces.com/contest/1113

A. Sasha and His Trip

题意:

n个城市,城市分布在一条直线上且按升序排序,现在有个人开车从一号城市出发,车的油箱容量为v。

在每个城市都可以买油,但价格不一样:第i个城市买1单位的油花费i元。问最终从1到n花费的最少为多少。

题解:

贪心即可,尽量在前面的城市买油,最后一鼓作气到n号城市。

代码如下:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int N = 2e5+;
  5. int n,v;
  6. int main(){
  7. cin>>n>>v;
  8. int fir=,las=n-v;
  9. int ans=v;
  10. if(n-<=v){
  11. cout<<n-;
  12. return ;
  13. }
  14. for(int i=;i<=las;i++){
  15. ans+=i;
  16. }
  17. cout<<ans;
  18. return ;
  19. }

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,这应该是显而易见的。

具体见代码吧:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int N = 1e5+;
  5. int a[N];
  6. int n;
  7. int main(){
  8. scanf("%d",&n);
  9. int sum = ;
  10. for(int i=;i<=n;i++){
  11. scanf("%d",&a[i]);
  12. sum+=a[i];
  13. }
  14. int ans = sum;
  15. int mn = *min_element(a+,a+n+);
  16. sum-=mn;
  17. for(int i=;i<=n;i++){
  18. for(int j=;j<=a[i];j++){
  19. if(a[i]%j!=) continue ;
  20. ans=min(ans,sum-a[i]+a[i]/j+mn*j);
  21. }
  22. }
  23. cout<<ans;
  24. return ;
  25. }

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并且当前为偶数位置时,这也算一种情况。

具体代码如下:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int cnt[][<<];
  5. int main(){
  6. int n;
  7. cin>>n;
  8. vector <ll> a(n+);
  9. for(int i=;i<=n;i++) scanf("%I64d",&a[i]);
  10. ll sum=,ans=;
  11. cnt[][]=;
  12. for(int i=;i<=n;i++){
  13. sum^=a[i];
  14. ans+=cnt[i%][sum];
  15. cnt[i%][sum]++;
  16. }
  17. cout<<ans;
  18. return ;
  19. }

D. Sasha and One More Name

题意:

给出一个回文串,然后让你用最少的次数分割为几个部分,之后可以拼接出一个和原来不同的回文串。如果不能就输出"Impossible",否则输出最少次数。

题解:

不能的情况很好判断。

在判断可行性过后,可以证明次数最多只需要两次,考虑从两边同时往中间走的切法就行了。

也就是说,我们只需要判断只切一次是否可行。由于字符串的长度只有5000,O(n^2)暴力即可。

代码如下:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = ;
  4. string s;
  5. int l;
  6. bool is(string ss){
  7. int f=;
  8. for(int i=;i<l;i++){
  9. int j=l-i-;
  10. if(ss[i]!=ss[j]) f=;
  11. }
  12. return f&&ss!=s;
  13. }
  14. int main(){
  15. cin>>s;
  16. l=s.length();
  17. int f=;
  18. for(int i=;i<l;i++){
  19. if(l& && i==l/) continue ;
  20. if(s[i]!=s[]) f=;
  21. }
  22. if(f){
  23. puts("Impossible");
  24. return ;
  25. }
  26. f=;
  27. for(int i=;i<l;i++){
  28. string t1=s.substr(,i),t2=s.substr(i,l);
  29. t2+=t1;
  30. if(is(t2))f=;
  31. }
  32. if(f) cout<<<<endl;
  33. else cout<<<<endl;
  34. return ;
  35. }

Codeforces Round #539 (Div. 2) 题解的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  4. Codeforces Round #539 (Div. 2)

    Codeforces Round #539 (Div. 2) A - Sasha and His Trip #include<bits/stdc++.h> #include<iost ...

  5. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  6. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  7. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  8. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  9. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

随机推荐

  1. Spring Cloud(五):Hystrix 监控面板【Finchley 版】

    Spring Cloud(五):Hystrix 监控面板[Finchley 版]  发表于 2018-04-16 |  更新于 2018-05-10 |  在上一篇 Hystrix 的介绍中,我们提到 ...

  2. 爬虫1.6-selenium+HeadlessChrome

    目录 爬虫-selenium+HeadlessChrome 1. 浏览器处理步骤 2. headless-chrome初体验 3. 实战爬取淘宝镇.街道信息 爬虫-selenium+HeadlessC ...

  3. LeeCode第一次刷题(两数相加)

    题目描述 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数组 ...

  4. 【转载】Android 内存溢出如何发生的。

    [转载]Android 内存溢出如何发生的. 且谈Android内存溢出 前言 关于android的内存溢出在创新文档库中也有不少,网络上也有很多这方面的资料.所以这遍文章不算是正真意义上的创新,仅仅 ...

  5. STM32单片机是如何启动的?

    STM32单片机是如何启动的? STM32中的内存 STM32中的内存包含两块主要区域:flash memory(只读).static ram memory(SRAM,读写).其中,flash mem ...

  6. opencv打开视频文件出错

    使用C#调用mingw的so文件,在C++端使用opencv打开视频.这样的项目完成过了一个,第二次做的时候,发现opencv打开视频文件出错. 首先怀疑是opencv的opencv_ffmpeg24 ...

  7. POJ 3675 Telescope(简单多边形和圆的面积交)

    Description Updog is watching a plane object with a telescope. The field of vision in the telescope ...

  8. Median Weight Bead(最短路—floyed传递闭包)

    Description There are N beads which of the same shape and size, but with different weights. N is an ...

  9. Python 循环语句和运算符

    while 循环 while 条件 : //条件为True时,执行while下带有缩进的语句 语句1 语句2 语句3 for循环 for循环可以用来遍历某一对象(遍历:通俗点说,就是把这个循环中的第一 ...

  10. 模拟Excel同一列相同值的单元格合并

    背景 项目中有一个查询工作量,可以将查询的结果导出到Excel表中.在Excel工具中,有一个合并居中功能,可以将选中的单元格合并成一个大的单元格.现在需要在程序中直接实现查询结果的汇总, 问题分析 ...