Educational Codeforces Round 84 (Rated for Div. 2), problem: (A) Sum of Odd Integers

A.

被卡了好久,样例的第一感觉n%k==0则YES

后来写式子,交了发n>=k*k 虽然写的时候也注意到了n-k必须是偶数(k个奇数和的奇偶性与k相同,故n与k奇偶性相同)

最后才想到,可以构造 前k-1个数为1~k-1 剩下的即为第k个数

#include<bits/stdc++.h>
#define ll long long
using namespace std;
//const int N=1e4+5;

int main(){
    int T;
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>T;
    while(T--){
        ll n,k;
        cin>>n>>k;
        if(n>=k*k&&n%2==k%2)cout<<"YES"<<endl;
         else cout<<"NO"<<endl;
    }
    return 0;
}

比赛时交的

#include<bits/stdc++.h>
#define ll long long
using namespace std;
//const int N=1e4+5;

int main(){
    int T;
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>T;
    while(T--){
        ll n,k;
        cin>>n>>k;
        if((n-(k-1)*(k-1))%2&&(n-(k-1)*(k-1))>=2*k-1)cout<<"YES"<<endl;
         else cout<<"NO"<<endl;
    }
    return 0;
}

B

原文地址:https://www.cnblogs.com/wyh447154317/p/12568503.html

时间: 2024-10-07 17:09:52

Educational Codeforces Round 84 (Rated for Div. 2), problem: (A) Sum of Odd Integers的相关文章

C - Game with Chips.Educational Codeforces Round 84 (Rated for Div. 2)

http://codeforces.com/contest/1327/problem/C 题意 给你一个图和一堆点,然后问你这一堆点和一堆目标点怎么才能到达这些目标点至少一次. 做法 其实题目已经给你提示了,上面说移动次数不大于2nm. 其实在2nm内就能把图上所有位置遍历一遍. 简单来说就是不管你脑洞开的有多大,没有用.该暴力还是得暴力. 先把最右上角的点移动到左下角,再按照s型移动到原始位置 就能保证所有点都经历过这个图上别的所有点了. 代码 #include <iostream> usi

Educational Codeforces Round 84 (Rated for Div. 2) C. Game with Chips(思维题)

Petya has a rectangular Board of size n×mn×m . Initially, kk chips are placed on the board, ii -th chip is located in the cell at the intersection of sxisxi -th row and syisyi -th column. In one action, Petya can move all the chips to the left, right

Educational Codeforces Round 84 (Rated for Div. 2)

原题链接 目录 题外话 A A题意 A思路 A代码 B 题意 思路 代码 C 题意 思路 代码 E 题意 思路 代码 题外话 被教育了,读题不认真,明明能四题的(靠),竟然打不过jy,很烦 A A题意 给你n,m(m是奇数的数量)问你是否可以使用m个奇数(不相同的)构成n A思路 自己上来以为是判断奇偶就死了 其实还有点其他的东西,比如k个互不相同的奇数最小就是k*k(记录一下) A代码 #include <bits/stdc++.h> #include <ext/pb_ds/assoc

Educational Codeforces Round 84 (Rated for Div. 2) A-E题解

A. Sum of Odd Integers 首先可以算出从1开始到第k个奇数之和.如果和大于n,则不可能存在k个奇数加和等于n,否则用n减去前k个奇数的和,这个差值若是偶数,直接加到最大的奇数上,就可以满足题意要求,否则输出no. 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 int main(){ 5 int t; 6 cin>>t; 7 while(t--){ 8 ll n

Educational Codeforces Round 84 (Rated for Div. 2)E(组合数学)

1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 const int mod = 998244353; 5 long long p[200007]; 6 int main(){ 7 ios::sync_with_stdio(false); 8 cin.tie(NULL); 9 cout.tie(NULL); 10 int n; 11 cin>>n; 12 p[0]=1;

Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum

https://codeforces.com/contest/1073/problem/E 题意 求出l到r之间的符合要求的数之和,结果取模998244353 要求:组成数的数位所用的数字种类不超过k种 思路 这题一看就是个数位dp的模板题,但是由于以前没有完全理解数位dp加上xjb套模版,导致样例都没算出来 一开始这样定义状态 dp[i][j] 代表第cnt-i(高位到低位)位,cnt~i状态为j的总和 一直记录当前数字的数值,到边界的时候返回加到答案中,但是由于这样定义状态会导致一个状态对应

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ