今日codeforces刷题(1)

一、前言

新栏目,每隔几天就保质保量地刷个10道codeforces题左右的样子

筛选1200-1500难度的题,然后按通过题目的人数降序排列的前10题

二、题目总览

三、具体题目

3.1 25A. IQ test

我的代码

看奇数出现的次数为1还是偶数出现的次数为1,然后输出与其他数奇偶性不同的数的下标

// Problem: A. IQ test

// Contest: Codeforces - Codeforces Beta Round 25 (Div. 2 Only)

// URL: https://codeforces.com/problemset/problem/25/A

// Memory Limit: 256 MB

// Time Limit: 2000 ms

//

// Powered by CP Editor (https://cpeditor.org)

#include

using i64 = long long;

using pii = std::pair;

constexpr int N = 1e5+5,M = 1e6+5,INF = 0x3f3f3f3f;

void solve(){

int n;std::cin >> n;

std::vector v;

int cnt0 = 0,cnt1 = 0;

for(int i = 0;i

int num;std::cin >> num;

v.emplace_back(num);

if(num&1) ++cnt1;

else ++cnt0;

}

if(cnt1==1){

for(int i = 0;i

if(v[i]&1){

std::cout << i+1 << '\n';

break;

}

}

}

if(cnt0==1){

for(int i = 0;i

if((v[i]&1)==0){

std::cout << i+1 << '\n';

break;

}

}

}

}

int main(){

std::cin.tie(nullptr)->sync_with_stdio(false);

int t = 1;

// std::cin >> t;

for(int ti = 0;ti

solve();

}

return 0;

}

3.2 4C. Registration system

我的代码

注意不能无脑用std::unordered_set来做,会超时;没有出现过的字符串,给cnt数组初始化为0,出现过的字符串根据它出现过的次数来设置cnt

// Problem: C. Registration system

// Contest: Codeforces - Codeforces Beta Round 4 (Div. 2 Only)

// URL: https://codeforces.com/problemset/problem/4/C

// Memory Limit: 64 MB

// Time Limit: 5000 ms

//

// Powered by CP Editor (https://cpeditor.org)

#include

using i64 = long long;

using pii = std::pair;

constexpr int N = 1e5+5,M = 1e6+5,INF = 0x3f3f3f3f;

void solve(){

int n;std::cin >> n;

std::set set;

std::unordered_map map;

int idx = 1;

std::vector cnt(N,0);

for(int i = 0;i

std::string s;std::cin >> s;

if(set.find(s)==set.end()){

set.insert(s);

map[s] = idx++;

cnt[map[s]];

std::cout << "OK\n";

}else{

int cur = cnt[map[s]];

std::string tmp = s+std::to_string(++cnt[map[s]]);

std::cout << tmp << '\n';

}

}

}

int main(){

std::cin.tie(nullptr)->sync_with_stdio(false);

int t = 1;

// std::cin >> t;

for(int ti = 0;ti

solve();

}

return 0;

}

3.3 230B. T-primes