# Codeforces Round 747

## A:Consecutive Sum Riddle

### Solution

$$l = 1-n,r=n$$ 即可，容易发现答案恰好为 $$n$$

### Code

inline void solve() {
int_fast64_t n ;
in(n),out(' ',-(n - 1),n) ;
fastio::putc('\n') ;
}

## B:Special Numbers

### Description

$$p$$$$n$$ 的特殊数，则 $$p=n^{q_0}+n^{q_1}+\cdots+n^{q_m}(q_i\ge 0)$$ 且所有 $$q_i$$ 互不相同。

### Code

inline void solve() {
int n,k,ans = 0;
cin >> n >> k ;
std::vector<int> bit ;
while (k) {
bit.push_back(k & 1);
k >>= 1;
}
for (int i = 0; i < bit.size(); ++i)
ans = (ans + fp(n,i) * bit[i]) % mod ;
cout << ans << '\n' ;
}

## C:Make Them Equal

### Solution

• 如果都是 $$c$$，那么次数为 $$0$$

### Code

inline void solve() {
cin >> n >> c >> (s + 1) ;
int f = 0 ;
for (int i = 1; i <= n; ++i)
if (s[i] != c) {
f = 1;
break ;
}
if (!f)
return cout << "0\n",void() ;
for (int i = 2; i <= n; ++i) {
int f = 0;
for (int j = i; j <= n; j += i) {
if (s[j] != c) {
f = 1;
break ;
}
}
if (f == 0)
return cout << "1\n" << i << '\n',void() ;
}
cout << 2 << "\n" << n << " " << n - 1 << '\n';
}

## D:The Number of Imposters

### Description

$$n$$ 个人，每个人有一种身份，身份只有 impostercrewmate 两种，$$m$$ 种关系，关系分为两种：

x y imposter$$x$$ 认为 $$y$$imposter

x y crewmate$$x$$ 认为 $$y$$crewmate

### Code

void dfs(int now) {
for (auto it : v[now]) {
if (col[it] == col[now])
return ok = false,void() ;
if (col[it] == -1) {
col[it] = col[now] ^ 1 ;
if (it <= n) ++t[col[it]] ;
dfs(it) ;
}
}
}

namespace {

inline void solve() {
int cnt,ans = 0;
cin >> n >> m, ok = 1,cnt = n;
for (int i = 1; i <= n + m; ++i) col[i] = -1 ;
for (int i = 1; i <= n + m; ++i) v[i].clear() ;
for (int i = 1,x,y; i <= m; ++i) {
char s[10] ;
cin >> x >> y >> s;
if (s[0] == 'i')
v[x].push_back(y),v[y].push_back(x) ;
else
v[x].push_back(++cnt),v[cnt].push_back(x),v[y].push_back(cnt),v[cnt].push_back(y) ;
}
for (int i = 1; i <= n; ++i) {
if (col[i] != -1)
continue ;
t[0] = 1,t[1] = 0,col[i] = 0;
dfs(i) ;
ans += max(t[0],t[1]) ;
}
if (!ok) ans = -1 ;
cout << ans << '\n' ;
}

inline void HL() {
int t;
cin >> t ;
for (; t; --t)
solve() ;
}

}
posted @ 2021-10-09 19:45  feicheng  阅读(19)  评论(0编辑  收藏  举报