首页 > 其他分享 >Codeforces-1005C

Codeforces-1005C

时间:2024-03-16 10:58:55浏览次数:32  
标签:int Codeforces ++ flag num ans need 1005C

https://codeforces.com/problemset/problem/1005/C

一、代码

目录

#include <bits/stdc++.h>
using namespace std;
void solve(){
    int a[122222], n, ans = 0;
    map<int, int> m;
    scanf("%d", &n);
    for (int i = 0;i < n;i ++){
        scanf("%d", &a[i]);
        m[a[i]] ++;
	}
	for (int i = 0;i < n;i ++){
        bool flag = 1;
        long long num = 1;
        for (int j = 1;j <= 31;j ++){
            int need = num - a[i];
            if ((need == a[i] and m[need] >= 2) or (need != a[i] and m[need] >= 1)){
				flag = 0;
				break;
			} 
            num *= 2;
        }
        ans += flag;

    }
    printf("%d", ans);
}
int main(){
	int T;
	T = 1;
	while(T--) solve();
	return 0;
}
// 该题方法与CSES-1640 相近

标签:int,Codeforces,++,flag,num,ans,need,1005C
From: https://blog.csdn.net/yaomotong/article/details/136719949

相关文章

  • Educational Codeforces Round 163 (Rated for Div. 2)
    EducationalCodeforcesRound163(RatedforDiv.2)A-SpecialCharacters解题思路:一个相同的连续段会贡献两个特殊字符,所以答案一定是偶数,找个不同的数分隔开即可。代码:#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;usingpii=pair<ll,ll......
  • Codeforces Round 933 (Div. 3)赛后总结
    CodeforcesRound933(Div.3)B从边缘开始计算,因为边缘肯定只能一个一个减,就可以遍历得到答案.代码C只要对mapie特判,然后判断map和pie的个数就是答案了。D(记忆化搜索)可以通过二维数组来标记搜索状态,将已经出现过的状态直接返回,极大减少时间。#include<bits/stdc++.h>......
  • Codeforces Round 933 (Div. 3) A - G 题解
    CodeforcesRound933(Div.3)A-RudolfandtheTicketSolution因为\(n\)很小,直接枚举\(b_i+c_j\)所产生的所有数字Code#include<bits/stdc++.h>usingnamespacestd;voidsolve(){intn,m,k;cin>>n>>m>>k;intans=0;......
  • CodeForces 1874E Jellyfish and Hack
    洛谷传送门CF传送门显然\(\text{fun}(P)_{\max}=\frac{|P|(|P|+1)}{2}\)。考虑大力dp,设\(f_{i,j,k}\)为\(|P|=i\),\(P_1=j\),\(\text{fun}(P)=k\)的排列\(P\)的个数。此时\(|L|=j-1,|R|=i-j\)。转移枚举\(L_1,R_1,\text{fun}(L),\text{fun}(R......
  • Codeforces Round 933 (Div. 3)
    CodeforcesRound933(Div.3)AA-RudolfandtheTicket暴力查看代码voidsolve(){intn,m,k;cin>>n>>m>>k;vector<int>b(n),c(m);for(inti=0;i<n;++i)cin>>b[i];for(inti=0;i<m;++i)cin>>c[i];......
  • Codeforces Round 933 (Div. 3)
    CodeforcesRound933(Div.3)A-RudolfandtheTicket解题思路:暴力。代码:#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;usingpii=pair<ll,ll>;#definefifirst#definesesecondusingpiii=pair<ll,pair<ll,ll>&......
  • Codeforces Round 933 (Div. 3)
    A.RudolfandtheTicket#include<bits/stdc++.h>usingnamespacestd;usingi32=int32_t;usingi64=longlong;usingldb=longdouble;#defineinti64usingvi=vector<int>;usingpii=pair<int,int>;constintinf=1e9;co......
  • Codeforces Round 933 (Div. 3) A-F
    CodeforcesRound933(Div.3)A.RudolfandtheTicket题意:有两个数组\(b_n\)和\(c_m\),两个数组中分别取一个数相加是否小于k,有几种方法使\(b_f\)+\(c_s\)<=k思路:暴力枚举所有方案,时间复杂度O(nm)代码:#include<bits/stdc++.h>usingnamespacestd;constintMAXN=1e......
  • Codeforces Round 656 (Div. 3) F. Removing Leaves
    ProblemDescription给出一棵\(n\)个节点的无根树。你可以进行以下操作:选择\(k\)个共同父节点的叶子节点,将\(k\)个节点和与父节点相连的边删去。求最大操作次数。Input第一行输入一个整数\(t\)\((1\let\le2\times10^4)\),表示测试组数。接下来每组测试数据第......
  • Codeforces Round 932 (Div. 2)
    目录写在前面ABCDE写在最后写在前面比赛地址:https://codeforces.com/contest/1935。被精心构造的C的样例鲨了的一集。妈的天使骚骚☆REBOOT完全就是他妈拔作啊我草,要是被人知道我他妈推了全线要被笑话一辈子吧、、、A签到。操作偶数次,则答案仅可能为s或reverse(s)+s......