首页 > 其他分享 >Educational Codeforces Round 15

Educational Codeforces Round 15

时间:2023-01-10 23:13:55浏览次数:66  
标签:Educational 15 int Codeforces long len ans using include

Educational Codeforces Round 15

https://codeforces.com/contest/702
3/6:ABC 不会小学数学,基础差前面写的慢

A. Maximum Increase

#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 5;
int a[N], n, ans, len = 1;

int main () {
    cin >> n;
    for (int i = 1; i <= n; i++)    cin >> a[i];
    for (int i = 2; i <= n; i++) {
        if (a[i] > a[i-1])  len ++;
        else {
            ans = max (ans, len);
            len = 1;
        }
    }
    ans = max (ans, len);
    cout << ans;
}

B. Powers of Two

#include <bits/stdc++.h>
#define int long long

using namespace std;
typedef pair<int, int> pii;
const int N = 1e5 + 5;
int a[N], n, ans;
int pw2[] = {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648};

signed main () {
    map<int, int> mp;
    cin >> n;
    for (int i = 1; i <= n; i++)    cin >> a[i], mp[a[i]] ++;
    sort (a + 1, a + n + 1);
    //for (int i = 1; i <= n; i++)    cout << a[i] << ' ';    cout << endl;
    
    // int x = 1;
    // while (x <= 2e9) {
    //     x *= 2;
    //     cout << x << ", ";
    // }

    for (int i = 1; i < n; i++) {
        mp[a[i]] --;
        //可以取到的范围: [a[i]+a[i+1], a[i]+a[n]]
        int l = a[i] + a[i+1], r = a[i] + a[n];
        int ed = *lower_bound (pw2, pw2 + 31, r);
        int st = *lower_bound (pw2, pw2 + 31, l); //[st, ed)
        //cout << st << ' ' << ed << endl;
        for (int j = st; j <= ed; j *= 2) {
            int find = j - a[i]; //找有多少个
            ans += mp[find];
        }
    }
    cout << ans << endl;
}

C. Cellular Network

#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 1e5 + 5, inf = 1e9 + 5;
int a[N], n, m, x, ans, dist;

signed main () {
    vector <int> b;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)    cin >> a[i];
    for (int i = 1; i <= m; i++)    cin >> x, b.push_back (x);
    sort (b.begin (), b.end ());
    //for (int i = 1; i <= m; i++)    cout << b[i] << ' ';    cout << endl;

    for (int i = 1; i <= n; i++) {
        //二分最近的左右点
        auto it = lower_bound (b.begin (), b.end (), a[i]);
        if (it == b.end ())     dist = a[i] - *prev(it);
        else if (it == b.begin ())  dist = *it - a[i];
        else    dist = min (*it - a[i], a[i] - *prev(it));
        //cout << *l << ' ' << *r << ' ' << dist << endl;
        ans = max (ans, dist);
    }
    cout << ans << endl;
}

//sort b, 二分
//计算每个cly到最近站的距离, 取max

D. Road to Post Office

#include <bits/stdc++.h>
#define int long long

using namespace std;
int d, k, a, b, t, ans; // a车b人

signed main() {
    cin >> d >> k >> a >> b >> t;
    if (k > d)    ans = a * d; //直接开车到了
    else {
        ans = min(k * a + b * (d - k), d * a + t * (d / k)); //开车k公里, 再走路; 全部开车
        ans = min(ans, (d % k) * b + t * (d / k - 1) + a * (d - d % k)); //在最后一次要修车的时候,开始走路
    }
    cout << ans << endl;
}

//烦人的小学数学题
//坑点:到站了也要修

E. Analysis of Pathes in Functional Graph

F. T-Shirts

标签:Educational,15,int,Codeforces,long,len,ans,using,include
From: https://www.cnblogs.com/CTing/p/17041634.html

相关文章

  • Codeforces Round #843 (Div. 2)
    CodeforcesRound#843(Div.2)https://codeforces.com/contest/1775CD都不会写的垃圾罢了A1.GardenerandtheCapybaras(easyversion)#include<bits/stdc++.h>......
  • Codeforces Round #843 (Div. 2) 题解
    A题目大意给你一个只含字母a,b字符串,要把它拆分成三段,使得其中间那段要么同时小于等于两边要么同时大于等于两边。题解由于只有a,b我们可以分讨解决如果\([2,......
  • 01.09-01.15文献阅读总结
    ......
  • leetcode215-数组中的第K个最大元素
    思路我自己想到的是用排序,然后取下标为n-k的数字,但是这样时间复杂度是O(nlogn),不符合题目要求题解中的快速排序法很好,我也想到了快速排序,但是具体实现没有写出来要点......
  • 15. 3Sum [Medium]
    3SumGivenanintegerarraynums,returnallthetriplets[nums[i],nums[j],nums[k]]suchthati!=j,i!=k,andj!=k,andnums[i]+nums[j]+nums[k]==......
  • Educational Codeforces Round 141 (Rated for Div. 2)(B,C,D)
    EducationalCodeforcesRound141(RatedforDiv.2)(B,C,D)BB这个题的大意是我们需要构造一个矩阵,我们需要这个矩阵的一个位置和它相邻位置的绝对值的不同数量最多我猜......
  • Educational Codeforces Round 141 (Rated for Div. 2)
    A-MakeitBeautiful题意:给出一个序列a,要求重新排列它,使前\(i-1\)个数之和不等于\(a_i\)思路:数据范围很小。用桶存数字,然后由大到小每种数字为一组循环输出即可赛时......
  • 2023.1.9(Educational Codeforces Round 141 & NEERC2017)
    A.YetAnotherTournamentLinkhttps://codeforces.com/contest/1783/problem/CStatement除了你以外有\(n\)个人,编号为\(0\ton-1\),每个人有两个权值\(a_i\)和......
  • 15个最好用的Node.JS后端框架
    15个最好用的Node.JS后端框架API和generators,全栈框架,大量的服务器库,它完全能够提供Web服务,无需使用Apache等外部软件。JavaScript引擎,很大一部分是用基本模块的JavaScrip......
  • Codeforces Round #645 (Div. 2) A-D
    A.ParkLighting题意:用1*2的方格去填充n*m的格子,可以重叠摆放,至少需要多少个分析:不重叠的情况下,横着摆与竖着摆的最少数量是一样的,贡献为\(\lfloor\frac{n......