A. Add Odd or Subtract Even

思路:

相同直接为0,如果两数相差为偶数就为2,奇数就为1

  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4. int main(){
  5. int kk;
  6. scanf("%d",&kk);
  7. while(kk--){
  8. int n,m;
  9. cin>>n>>m;
  10. if(n==m) {printf("0\n");continue;}
  11. if(m-n>){
  12. if((m-n)%){cout<<<<endl;continue;}
  13. else {cout<<<<endl;continue;}
  14. }
  15. if(!((n-m)%)) {
  16. cout<<<<endl; continue;}
  17. else cout<<<<endl;
  18. }
  19. }

B. WeirdSort

思路:

记录哪些位置可以交换,然后不断循环遍历数组直到没有交换发生,最后再判断一下是否符合要求即可,最坏时间复杂度为冒泡排序O(N2)

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<vector>
  4. #include<cstring>
  5. #define inf 0x3f3f3f3f
  6. using namespace std;
  7. typedef long long ll;
  8. const int maxn=;
  9. int a[maxn],b[maxn],flag[maxn];
  10. int main()
  11. {
  12. int t;
  13. scanf("%d",&t);
  14. while(t--){
  15. memset(flag,,sizeof(flag));
  16. int n,m;
  17. scanf("%d%d",&n,&m);
  18. for(int i=;i<=n;i++) scanf("%d",&a[i]);
  19. for(int i=;i<=m;i++) scanf("%d",&b[i]),flag[b[i]]=;
  20. int num=;
  21. while(num){
  22. num=;
  23. for(int i=;i<=n;i++){
  24. if(flag[i]){
  25. if(a[i]>a[i+]){
  26. num=;
  27. swap(a[i],a[i+]);
  28. }
  29. }
  30. }
  31. }
  32. int kk=;
  33. for(int i=;i<n;i++)
  34. if(a[i]>a[i+]) kk=;
  35. if(kk) cout<<"NO"<<endl;
  36. else cout<<"YES"<<endl;
  37. }
  38. return ;
  39. }

C. Perform the Combo

思路:

根据会按错的位置,我们开个数组mp[i] 记录下犯错位置i的次数,然后一个数组c 来维护前缀和按错的字母的总和 然后每次碰到mp[i] 有值的话,我们去循环26个字母,把答案数组a加上当前维护的前缀的c*mp[i] 也就是当前位置犯错的次数就好了

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstring>
  4. using namespace std;
  5. typedef long long ll;
  6. ll mp[];
  7. int b[];
  8. char s[];
  9. int main()
  10. {
  11. int t;
  12. cin>>t;
  13. while(t--)
  14. {
  15. ll a[]={};
  16. ll c[]={};
  17. int n,m;cin>>n>>m;
  18. cin>>s+;
  19. for(int i=;i<=n;i++) mp[i]=;
  20. for(int i=;i<=m;i++){
  21. cin>>b[i];
  22. mp[b[i]]++;
  23. }
  24. for(int i=;i<=n;i++){
  25. a[s[i]]++;
  26. c[s[i]]++;
  27. if(mp[i]){
  28. for(int j='a';j<='z';j++){
  29. a[j]=a[j]+(mp[i]*c[j]);
  30. }
  31. }
  32. }
  33. for(int i='a';i<='z';i++) cout<<a[i]<<" ";
  34. puts("");
  35.  
  36. }
  37. return ;
  38. }

D. Three Integers

思路:

枚举i,然后枚举i的倍数j,再枚举j的倍数k,找到最小值即可,注意枚举范围一定要大

  1. #include<iostream>
  2. #include<algorithm>
  3. #define inf 0x3f3f3f3f
  4. using namespace std;
  5. int main()
  6. {
  7. int t,a,b,c;
  8. scanf("%d",&t);
  9. while(t--){
  10. scanf("%d%d%d",&a,&b,&c);
  11. int ans=inf,x=,y=,z=;
  12. for(int i=;i<=;i++){
  13. for(int j=i;j<=;j+=i){
  14. for(int k=j;k<=;k+=j){
  15. int kk=abs(a-i)+abs(b-j)+abs(c-k);
  16. if(kk<ans){
  17. ans=kk,x=i,y=j,z=k;
  18. }
  19. }
  20. }
  21. }
  22. cout<<ans<<endl;
  23. cout<<x<<" "<<y<<" "<<z<<" "<<endl;
  24. }
  25. return ;
  26. }

F. Moving Points(树状数组+离散化)

思路:

如果Posx < Pos&&V< Vy 那么两点的距离最小值就会为0,否则都为坐标的差值,那答案就是统计∑dis(i,j) (Pos< Posj && V≤ Vj

看到位置跟速度的范围很大,首先将二者离散化,然后先按照坐标排序

一个点对答案的贡献就为所有坐标比他小并且速度比他小的点距离差值的和,所以就成了一个偏序问题

开两个树状数组sum[0][x]记录速度小于x的点的个数,sum[1][x]记录速度小于x的点的坐标和 动态加点就好了

  1. #include<iostream>
  2. #include<algorithm>
  3. #define lowbit(x) (x&(-x))
  4. using namespace std;
  5. typedef long long ll;
  6. const int maxn=2e5+;
  7. struct node{
  8. int x,v;
  9. }a[maxn];
  10. int speed[maxn],n;
  11. ll sum[][maxn];
  12. int cmp(node a,node b){return a.x<b.x;}
  13. void add(int x,int val)
  14. {
  15. while(x<=n){
  16. sum[][x]++,sum[][x]+=val;
  17. x+=lowbit(x);
  18. }
  19. }
  20. ll query(int x,int k)
  21. {
  22. ll ans=;
  23. while(x>=){
  24. ans+=sum[k][x];
  25. x-=lowbit(x);
  26. }
  27. return ans;
  28. }
  29. int main()
  30. {
  31. scanf("%d",&n);
  32. for(int i=;i<=n;i++) scanf("%d",&a[i].x);
  33. for(int i=;i<=n;i++) scanf("%d",&a[i].v),speed[i]=a[i].v;
  34. sort(a+,a++n,cmp);
  35. sort(speed+,speed++n);
  36. unique(speed+,speed++n);
  37. ll ans=;
  38. for(int i=;i<=n;i++){
  39. int now=lower_bound(speed+,speed++n,a[i].v)-speed;
  40. ans+=a[i].x*query(now,)-query(now,);
  41. add(now,a[i].x);
  42. }
  43. cout<<ans<<endl;
  44. return ;
  45. }

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

  1. Codeforces Round #624 (Div. 3)(题解)

    Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...

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

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

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

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

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

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

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

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

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

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

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

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

  8. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  9. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

随机推荐

  1. Mysql安装维护笔记一

    1.Centos7安装mysql rpm安装PHP7相应的yum源 $wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11. ...

  2. java_05_IO

    java_05_IO 1,动手动脑 使用Files. walkFileTree()找出指定文件夹下所有大于指定大小(比如1M)的文件. 分析思路: 1)找到该文件夹下所有文件. 2)找出其中字节数大于 ...

  3. schema 文件约束

    1. 在javaproject 中创建一个.xsd 文件 <?xml version="1.0" encoding="UTF-8" ?> <! ...

  4. 剑指offer_12.31_Day_1

    不用加减乘除做加法 题目描述 写一个函数,求两个整数之和,要求在函数体内不得使用+.-.*./四则运算符号.   不用四则运算,必然是依靠位运算. 位运算包括,与,或,异或,取反,左移,右移. 分别为 ...

  5. (简单模拟)P1540 机器翻译

    题解: #include<iostream>#include<cmath>using namespace std; int main(){ int m,n; cin>&g ...

  6. promise核心技术 2.两种回调函数 js中error的处理

    抽空详细学习一下什么是回调函数(一个回调函数,也被称为高阶函数) 1.什么样的函数是回调函数 自己定义的(sittimeout不是自己定义的) 没有调用 自己执行 1.同步回调与异步回调函数 同步回调 ...

  7. unix中嘚vim编辑器

    在linux家族中,vim编辑器是系统自带的文本编辑器,其功能强大自不必说了. 偶有小白,刚接触linux,要修改某个文本文件,不可能像WINDOWS那样操作,更有甚者,进入VI编辑器后,无法退出以致 ...

  8. java8中的map 和reduce

    map 1.使用map让集合里面的数字翻倍. List<Integer> numbers = Lists.newArrayList(1,2,3,4,5);List<Integer&g ...

  9. 74)搭建TCP服务器

    补充: 1-->listen是监听,就是监听你建立的那个socket那个窗口,要是有客户端来了,那么就把他加到 队列里面,然后accept是从队列中取客户端(就是把对应的客人的信息拿过来,交给w ...

  10. 学习SEO之7天精通SEO

    这本书大致看了一下,对于SEO基本上有了一个初步的认识,附上链接以供学习之用. 百度网盘:https://pan.baidu.com/s/1Bntzh2YF4tBd2AYAL1Q8vQ 心得:1.SE ...