第十届题目

组队

cs 复制代码
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  printf("490");
  return 0;
}

年号字串

cs 复制代码
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  printf("BYQ");
  return 0;
}

数列求值

cs 复制代码
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  printf("4659");
  return 0;
}

数的分解

cs 复制代码
#include <stdio.h>
#include <stdlib.h>

int check(int x)
{
  while(x)
  {
    if(x%10==2||x%10==4) return 0;
    x/=10;
  }
  return 1;
}

int main(int argc, char *argv[])
{
  int cnt=0;
  for(int x=1;x<=2019/3;x++)
  {
    if(check(x))
    {
      for(int y=x+1;y<=(2019-x)/2;y++)
      {
        if(check(y))
        {
          int z=2019-x-y;
          if(z>y&&check(z)) cnt++;
        }
      }
    }
  }
  printf("%d",cnt);
  return 0;
}

特别数的和

cs 复制代码
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  long long sum=0;
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
  {
    int t=i;
    int flag=0;
    while(t)
    {
      if(t%10==2||t%10==0||t%10==1||t%10==9)
      {
        flag=1;
        break;
      }
      t/=10;
    }
    if(flag) sum+=(long long)i;
  }
  printf("%lld",sum);
  return 0;
}

完全二叉树的权值

cs 复制代码
#include <stdio.h>
#include <math.h>
#include <limits.h>

#define MAX 100005

int main(int argc, char *argv[])
{
  int n;
  scanf("%d",&n);
  int a[100005];
  for(int i=1;i<=n;i++)
  {
    scanf("%d",&a[i]);
  }
  int depth=1;
  int ans_depth=1;
  int start=1,end=1;
  int max=-100000;
  while(end<n)
  {
    int sum=0;
    end=pow(2,depth)-1;
    if(end>n) end=n;
    for(int i=start;i<=end;i++)
    {
      sum+=a[i];
    }
    if(sum>max) 
    {
      max=sum;
      ans_depth=depth;
    }
    start=end+1;
    depth++;
  }
  printf("%d",ans_depth);
  return 0;
}

等差数列

cs 复制代码
#include <stdio.h>
#include <stdlib.h>

#define MAX 100005

int cmp(const void *a,const void *b)
{
  long long pa=*(long long*)a;
  long long pb=*(long long*)b;
  return (pa>pb)-(pa<pb);
}

long long gcd(long long a,long long b)
{
  while(b)
  {
    long long t=b;
    b=a%b;
    a=t;
  }
  return a;
}

int main(int argc, char *argv[])
{
  int n;
  scanf("%d",&n);
  long long a[100005];
  for(int i=0;i<n;i++)
  {
    scanf("%lld",&a[i]);
  }
  qsort(a,n,sizeof(long long),cmp);
  if(a[0]==a[n-1]) 
  {
    printf("%d",n);
    return 0;
  }
  if(n==1)
  {
    printf("1");
    return 0;
  }
  long long d=a[1]-a[0];
  for(int i=2;i<n;i++)
  {
    d=gcd(d,a[i]-a[i-1]);
  }
  long long x=(a[n-1]-a[0])/d+1;
  printf("%lld",x);
  return 0;
}

后缀表达式

cs 复制代码
#include <stdio.h>
#include <stdlib.h>

int cmp(const void *a, const void *b) {
    long long pa = *(long long*)a;
    long long pb = *(long long*)b;
    return (pa > pb) - (pa < pb);
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    long long a[200005];
    int total = n + m + 1;
    
    for (int i = 0; i < total; i++) {
        scanf("%lld", &a[i]);
    }
    
    qsort(a, total, sizeof(long long), cmp);
    
    long long sum = 0;
    for (int i = 0; i < total; i++) {
        sum += a[i];
    }
    
    if (m == 0) {
        printf("%lld", sum);
        return 0;
    }
    
    if (a[0] >= 0) {
        // 全正数
        printf("%lld", sum - 2 * a[0]);
    } 
    else if (a[total - 1] <= 0) {
        // 全负数
        printf("%lld", -sum + 2 * a[total - 1]);
    } 
    else {
        // 有正有负
        long long abs_sum = 0;
        for (int i = 0; i < total; i++) {
            abs_sum += llabs(a[i]);
        }
        printf("%lld", abs_sum);
    }
    
    return 0;
}
相关推荐
y = xⁿ2 小时前
【LeetCode Hot100】动态规划:T70:爬楼梯 T118:杨辉三角形 T198:打家劫舍
算法·leetcode·动态规划
Liangwei Lin2 小时前
洛谷 P1460 [USACO2.1] 健康的荷斯坦奶牛 Healthy Holsteins
数据结构·算法
汀、人工智能2 小时前
02 - 变量与数据类型
数据结构·算法·链表·数据库架构··02 - 变量与数据类型
hello!树2 小时前
函数极限的概念和性质
算法
人道领域2 小时前
【LeetCode 刷题日】19.删除链表的倒数第n个节点
算法·leetcode·链表
小白zlm2 小时前
连续系统-离散系统的转换
算法·嵌入式·电机控制·pmsm
py有趣2 小时前
力扣热门100题之最大子数组和
算法·leetcode
汀、人工智能2 小时前
03 - 运算符
数据结构·算法·数据库架构·位运算·哈希表·03 - 运算符
小肝一下2 小时前
每日两道力扣,day4
c++·算法·leetcode·职场和发展