首页 > 其他分享 >Codeforces Round 886 (Div. 4)

Codeforces Round 886 (Div. 4)

时间:2023-07-22 09:45:55浏览次数:34  
标签:886 int res Codeforces long cin solve auto Div

A. To My Critics

#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve(){
    vector<int> a(3);
    for( auto & i : a )
        cin >> i;
    sort( a.begin(), a.end() );
    if( a[2] + a[1] >= 10 ) cout << "YES\n";
    else cout << "NO\n";
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t;
    cin >> t;
    while( t -- )
        solve();
    return 0;
}

B. Ten Words of Wisdom

#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve(){
    int n;
    cin >> n;
    vector<int> a(n+1) , b(n+1);
    for( int i = 1 ; i <= n ; i ++ )
        cin >> a[i] >> b[i];
    int res = -1 , val = -1;
    for( int i = 1 ; i <= n ; i ++ ){
        if( a[i] > 10 ) continue;
        if( b[i] > val ) val = b[i] , res = i;
    }
    cout << res << "\n";
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t;
    cin >> t;
    while( t -- )
        solve();
    return 0;
}

C. Word on the Paper

#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve(){
    vector<string> g(8);
    for( auto & i : g )
        cin >> i;
    for( const auto & i : g )
        for( const auto & j : i )
            if( j != '.' ) cout << j;
    cout << "\n";
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t;
    cin >> t;
    while( t -- )
        solve();
    return 0;
}

D. Balanced Round

#include <bits/stdc++.h>

using namespace std;


void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto &i: a)
        cin >> i;
    sort(a.begin(), a.end());
    int res = 0;
    for( int i = 0 , last = INT_MIN , cnt = 0; i < n ; i ++ ){
        if( a[i] - last <= k ) cnt ++;
        else cnt = 1;
        res = max( res , cnt );
        last = a[i];
    }
    cout << n - res << "\n";


}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

E. Cardboard for Pictures

\[c=\sum(s+2w)^2=\sum(s^2+4sw+4w^2)\\ 4nw^2+4\sum (s)w+\sum(s^2)-c=0 \]

解一元二次方程

import math


def solve():
    n, c = map(int, input().split(' '))
    s = list(map(int, input().split(' ')))
    a = 4 * n
    b , c = 0 , - c
    for i in s :
        b += i
        c += i * i
    b = b * 4
    res = (math.sqrt(b * b - 4 * a * c) - b) // ( 2 * a )
    print(int(res))


T = int(input())
while T > 0:
    T -= 1
    solve()

F. We Were Both Children

枚举陷阱,枚举陷阱的因子统计答案

#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1, x; i <= n; i++) {
        cin >> x;
        if (x > n) continue;
        a[x]++;
    }
    int res = 0;
    for (int i = 1, cnt = 0; i <= n; i++) {
        cnt = 0;
        for (int j = 1; j * j <= i; j++) {
            if (i % j != 0) continue;
            cnt += a[j];
            if (j != i / j)
                cnt += a[i / j];
        }
        res = max(res, cnt);
    }
    cout << res << "\n";
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

G. The Morning Star

统计每一行、每一列、每一主对角线、每一负对角线上的点的数量,然后组合数即可

#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve() {
    int n;
    cin >> n;
    map<int,int> a , b , c , d;
    for( int x , y ; n ;  n -- ){
        cin >> x >> y;
        a[x] ++ , b[y] ++ , c[x+y] ++ , d[x-y] ++;
    }
    int res = 0;
    for( auto [k,v] : a )
        res += v * (v-1) ;
    for( auto [k,v] : b )
        res += v * (v-1);
    for( auto [k,v] : c )
        res += v * (v-1);
    for( auto [k,v] : d )
        res += v * (v-1);
    cout << res << "\n";
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

H. The Third Letter

建无向图,然后任意确定一个点,按照图的顺序去确定其他点的位置,在确定点位置的过程中判断是否合法即可。

#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, int>>> g(n + 1);
    for (int i = 1, a, b, c; i <= m; i++) {
        cin >> a >> b >> c;
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, -c);
    }
    vector<int> d(n + 1, LLONG_MIN);
    for (int i = 1; i <= n; i++) {
        if( d[i] != LLONG_MIN ) continue;
        d[i] = 0;
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            int a = q.front();
            q.pop();
            for (auto [b, c]: g[a]) {
                if (d[b] != LLONG_MIN) {
                    if (d[b] != d[a] + c) {
                        cout << "NO\n";
                        return;
                    }
                } else {
                    d[b] = d[a] + c;
                    q.push(b);
                }
            }
        }
    }
    cout << "YES\n";
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

标签:886,int,res,Codeforces,long,cin,solve,auto,Div
From: https://www.cnblogs.com/PHarr/p/17572865.html

相关文章

  • Codeforces 1830E - Bully Sort
    这种题肯定首先要寻找不变量。显然后面排好序的后缀不会被改变。因此从整体上来看我们的流程肯定是,如果当前\(p_n=n\),就令\(n\)减一,否则你一步换的\(i\)肯定满足\(p_i=n\)。而显然\(\min\limits_{j=i}^np_j\lei\),因此我们考察\(\sum|i-p_i|\)和\(\sum\limits_{i<j}[p_......
  • Codeforces 794G - Replace All
    一个比较垃圾的做法,卡着时限过了这道题。首先大胆猜个结论:要么\(|s|=|t|\),此时\(A,B\)任取,要么存在字符串\(c\)和整数\(x,y\)使得\(A=c^x,B=c^y\),其中\(c^x\)表示\(x\)个\(c\)拼接得到的结果。证明的话感觉还挺复杂的,可能要border引理之类的东西,不过我是先写了个......
  • 洛谷 P8861 - 线段
    牛逼题。先考虑\(l\le10^5,10^5+1\ler\)的部分分:一种方法是线段树,即因为左右端点是独立的,因此对左右端点各维护一个权值线段树表示有多少个区间以这个值为左/右端点,这样对于修改,左端点的部分相当于先查询\(\lel\)的数的个数,然后将它们都挂到\(l\)上,最后把\(<l\)的部......
  • Vue3 响应式全局对象json 动态绑定界面三 (Div块样式 字符串叠加)
    效果 man.js  定义响应式全局对象 globalData//全局对象constglobalData=reactive({missedCallData:"",currentUserTel:"",})app.provide('globalData',globalData);在main.js的函数中改变missedCallData 的值从而改变界面列表//改变全局变量gl......
  • Vue3 响应式全局对象json 动态绑定界面四 (Div块样式 Json数据绑定)
    效果man.js  定义响应式全局对象 globalData//全局对象constglobalData=reactive({extTelTalkData:[{userExten:"1000",userName:"刘亦菲",callStatus:"通话"},{......
  • Codeforces 856F - To Play or not to Play
    首先,DP肯定是逃不掉的,因为直接贪心其实不好判断在两个人都可以上线的时间段究竟是哪个人上线,需要通过后面的情况来做出判断,但是这题值域比较大直接维护DP值肯定不行,因此考虑先设计一个与值域有关的DP然后优化。将时间区间离散化,然后依次考虑每个时间区间。一个很自然的想法......
  • Codeforces Round div.2 C
    Smiling&Weeping----我对姑娘的喜欢,何止钟意二字题目链接:Problem-C-Codeforces自我分析:我感觉这是一道很有意义的题目,可以帮我们更好的理解二进制的本质思路:首先先了解一下题目,我们是求由第i个数到末尾的异或和(异或:相同为0,不同为1),那么我......
  • Codeforces Round 882 div.2 B
    Smiling&Weeping----玫瑰花你拿才好看,风景要和你看才浪漫--<-<-<@B.HamonOdysseytimelimitpertest1secondmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputJonathanisfightingagainstDIO......
  • Codeforces 1696G - Fishingprince Plays With Array Again
    初读题目可以发现一些性质:每次操作会使整个序列的和减少至多\(X+Y\),因此\(ans\ge\dfrac{\suma_i}{X+Y}\)。对于两个不相邻位置\(a_i,a_j(|i-j|>1)\),每次操作最多使它们的和减少\(\max(X,Y)\)。然后你发现两个限制可以结合在一起使用,稍加思考可以得到一个比较普适的结论:......
  • jquery 设置 div不能点击
    如何使用jQuery设置div不能点击作为一名经验丰富的开发者,我将向你介绍如何使用jQuery来设置一个div不能点击。以下是整个过程的步骤:步骤动作1引入jQuery库2选择需要设置的div元素3给选中的div元素绑定点击事件4在点击事件处理程序中取消默认行为现在让......