首页 > 其他分享 >SMU Summer 2023 Contest Round 2

SMU Summer 2023 Contest Round 2

时间:2023-07-11 16:22:23浏览次数:42  
标签:Summer Contest int SMU a1 a3 a2 sum define

SMU Summer 2023 Contest Round 2

A. Treasure Hunt

当\(x1 - x2\)的差值与\(y1-y2\)的差值都能被\(x,y\)整除时,且商之和为2的倍数就一定可以到达

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define  inf 0x3f3f3f3f

using namespace std;

const int N = 2e5 + 10, mod = 1e18;
int n,m,t,k;
void solve(){
    int x1,y1,x2,y2,x,y;
    cin >> x1 >> y1 >> x2 >> y2 >> x >> y;

    int dx = x2 - x1, dy = y2 - y1;

    if(dx % x == 0 && dy % y == 0 && ((dx / x + dy / y) % 2 == 0)){
        cout << "YES" << endl;
    }else
        cout << "NO" << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int Ke_scholar = 1;
//    cin >> Ke_scholar;
    while(Ke_scholar--)
        solve();
    return 0;
}
/*
 */

B. Makes And The Product

对数组排序,显然前三个的积一定是最小的.

取前三个值为\(a1,a2,a3\),因为三种结果都只看\(a3\)的关系,记\(sum\)为\(a3\)的数量.

结果分三种情况 (实际上应该是四种,不过有两组重复了​:

  1. \(a1 = a2 = a3\) 时,说明三个是一样的,只需要在\(sum\)中任取三个即可,即\(C_{sum}^{3}\),也可以用公式\(\frac{sum * (sum - 1) * (sum - 2)}{6}\).
  2. \(a1 = a2 < a3\) 或者 $a1 < a2 < a3 $ 时,这两种都是一样的,因为前两个都是必须选,然后再从 \(sum\) 中选一个,答案就是 \(sum\) .
  3. \(a1 < a2 = a3\)时,则\(a1\)必选,然后\(a2,a3\)再从\(sum\)中任选两个即可,即\(C_{sum} ^ {2}\),也可以用公式\(\frac{sum * (sum - 1)}{2}\).
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define  inf 0x3f3f3f3f

using namespace std;

const int N = 2e5 + 10, mod = 1e18;
map<int, int > mp;
int n,m,t,k;
void solve(){
   cin >> n;
   vector<int> a(n);
   for(auto &i : a)
       cin >> i;
   sort(a.begin(), a.end());
   int a1 = a[0],a2 = a[1],a3 = a[2];
   int sum = 0;
   for(int i = 0;i < n;i ++){
       sum += (a[i] == a3);
   }
   int ans = 0;
   if(a1 == a2 && a2 == a3){
       ans = sum * (sum - 1) * (sum - 2) / 6;
   }else if(a1 == a2 && a2 < a3 || a1< a2 && a2 < a3){
       ans = sum;
   }else if(a1 < a2 && a2 == a3){
       ans = sum * (sum - 1)/ 2;
   }
   cout << ans << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int Ke_scholar = 1;
//    cin >> Ke_scholar;
    while(Ke_scholar--)
        solve();
    return 0;
}
/*
 */

C. Really Big Numbers

由于给定的大数在答案中是单调递增的,所以我们可以对答案进行二分,二分的左边界就是满足条件的最小的大数,这个数到\(n\)之间的都算大数,若左边界大于了n说明没有满足条件的

#include<bits/stdc++.h>
#define endl '\n'
#define int long long

using namespace std;

int n,m,t,k;
void solve(){
  int s;
  cin >> n >> s;

  auto get = [&](int x){
      int res = 0;
      while(x){
          res += x % 10;
          x /= 10;
      }
      return res;
  };

  int ans = 0, l = 1, r = 1e18;
  while(l <= r){
      int mid = (l + r) >> 1;
      if(mid - get(mid) >= s){
          r = mid - 1;
//          cout << mid << endl;
      }else l = mid + 1;
  }
  cout << (l > n ? 0 : n - l + 1) << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int Ke_scholar = 1;
//    cin >> Ke_scholar;
    while(Ke_scholar--)
        solve();
    return 0;
}
/*
 */

标签:Summer,Contest,int,SMU,a1,a3,a2,sum,define
From: https://www.cnblogs.com/Kescholar/p/17545069.html

相关文章

  • SMU 2023 Spring 题单 第二周 贪心
    Saruman'sArmy首先对序列排序,然后逐个考虑覆盖,如果要覆盖当前的点,则标记点越靠后越好,所有向后找\(R\),选择最靠后的标记,然后从标记点开始在向后找\(R\)也是被标记过的,直接跳过#include<cstdio>#include<algorithm>usingnamespacestd;intread(){intx=0,f=1......
  • [Leetcode Weekly Contest]351
    链接:LeetCode[Leetcode]6451.找出最大的可达成数字给你两个整数num和t。如果整数x可以在执行下述操作不超过t次的情况下变为与num相等,则称其为可达成数字:每次操作将x的值增加或减少1,同时可以选择将num的值增加或减少1。返回所有可达成数字中的最大值......
  • AtCoder Regular Contest 164 (A-C)
    A.TernaryDecomposition思维难度其实可以作为第二题思路先考虑最优情况下需要多少个数来组成(不够就No)在考虑全部为1的情况下是否可行(N<K这种情况不行)剩下的情况,考虑每次把高位的1向下挪变为3,所需的数字+2那么即三进制拆分后,在[min,max]范围内,且与最优情况差值为......
  • AtCoder Beginner Contest 309
    A:1#include<cstdio>2#include<cstring>3#include<algorithm>4#include<iostream>5#include<string>6#include<vector>7#include<stack>8#include<bitset>9#include<cstdlib>10#include......
  • AtCoder Beginner Contest 273 ABCD
    AtCoderBeginnerContest273A-ARecursiveFunctionProblemStatement题意:给你一个函数\(f(x)\)\(f(0)=1\)对于所有正整数\(k\),有\(f(k)=k*f(k-1)\)找到\(f(N)\)Solution思路:数据范围只有\(10\),直接递归。#include<bits/stdc++.h>usingnamespacestd;typede......
  • AtCoder Beginner Contest 309
    感觉F写了个乱搞做法A-Nine(abc309A)题目大意给定一个\(3\times3\)的网格,以及两个数字。问这两个数字是否水平相邻。解题思路求出两个数字的横纵坐标,看是否横坐标相同,纵坐标差一即可。读题不仔细,开题就WA了。神奇的代码#include<bits/stdc++.h>usingnamespa......
  • AtCoder Grand Contest 058 D Yet Another ABC String
    洛谷传送门AtCoder传送门OrzH6_6Q,感谢他给我们带来了这道容斥好题。这个东西看起来很不好搞。可以尝试容斥。但是我们要容斥啥?钦定ABC不出现,其他任意?感觉还是很难算。观察不合法子串,发现它们很有特点。如果我们钦定\(\texttt{A}\)为\(0\),\(\texttt{B}\)为\(1\),\(\te......
  • AtCoder Beginner Contest 308 题解
    https://atcoder.jp/contests/abc308/tasks_printA-NewScheme过水已隐藏。#include<bits/stdc++.h>#include<ext/pb_ds/assoc_container.hpp>#include<ext/pb_ds/tree_policy.hpp>#include<ext/pb_ds/hash_policy.hpp>usingnamespacestd;u......
  • AtCoder Beginner Contest 264 ABCDE
    AtCoderBeginnerContest264A-"atcoder".substr()ProblemStatement题意:截取字符串atcoder的[L,R]一段并输出。Solution题解:用string.substr直接写#include<bits/stdc++.h>usingnamespacestd;intmain(){ strings="?atcoder"; intl,r; cin&......
  • AtCoder Regular Contest 163
    A只需暴力判断能否分成两部分即可。时间复杂度\(\mathcal{O}(n^2)\)。B肯定是选值域连续的一段数操作,排序后枚举区间即可。时间复杂度\(\mathcal{O}(n\logn)\)。C场上降智了15min,我是什么shaber啊。注意到\(1=\frac1n+\sum_{i<n}\frac{1}{i(i+1)}\),但......