Homework Introduction
https://codeforces.com/blog/entry/66909
https://vjudge.net/
在线文档
https://kdocs.cn/l/cqWMDuRzD6h2
//全排列函数
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[11];
int n;
cin >> n;
for (int i = 0; i < n; i++)
a[i] = i + 1;
do {
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
cout << '\n';
} while (next_permutation(a, a + n));
//有下一个排列是返回值非0
}
两个骑士
考虑在n*n的方格中放置的全部方案
从n*n个格子里选两个
不合法的方案,要占用2*3的方格或3*2的方格
由于网格是n*n的,所以只需算一种
在n*n的方格中放2*3
在n长度中移动3,可以移动n-3+1次
在n长度中移动2,可以移动n-2+1次
所以 一共有(n-3+1)*(n-2+1)种,有两种放法*2
竖着放再加倍*2
两个集合
数字总和必须是偶数,假定总和一半sum
为了凑sum,可以从n->1枚举所有数字,如果这个数字>=sum可选
由于小于它的所有2的幂次在其左侧,一定能够保证剩余数字可凑
位串的快速幂解法
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll qpow(ll a, ll b, ll c) {
ll res = 1;
while (b != 0) {
if (b & 1)
res = res * a % c; //奇数时单独乘一次
b /= 2; //指数减半
a = a * a % c; //底数翻倍
}
return res;
}
int main() {
ll a, c = 1e9 + 7;
cin >> a ;
cout << qpow(2, a, c) << "\n";
}
Problem
Please claim the assignment to see the problems.
- Status
- Live...
- Problem
- 19
- Open Since
- 2025-5-1 0:00
- Deadline
- 2025-5-8 23:59
- Extension
- 24 hour(s)