题意:找出1-5号评分之和的最大值
注意:每个球员的成绩只能用一次,就是一个球员只能取一个成绩
#include
#include
#include
using namespace std;
const int N = 100;
int stu[N][N];
bool st[N];
int ans,x;
void dfs(int u,int sum){
if(u >= 6){
if(sum > ans) ans = sum;
return ;
}
for(int i = 1; i <= 20; i ++ ){
if(!st[i]){
st[i] = true;
dfs(u + 1,sum + stu[i][u]);
st[i] = false;
}
}
dfs(u + 1,sum);
}
int main(){
for(int i = 1; i <= 20; i ++ ){
cin >> x;
for(int j = 1; j <= 5; j ++ ){
cin >> stu[i][j];
}
}
dfs(1,0);
cout<
本题总结:手算挺快
题意:这是一道进制转换题(十进制转换为26进制)
#include
#include
#include
using namespace std;
char str[] = {" ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
int n;
string res;
void revd(int n,int d){
do{
res += str[n%d];
n/=d;
}while(n != 0);
for(int i = res.size()-1; i >= 0; i -- ){
cout<> n;
revd(n,26);
return 0;
}
总结:难点在于怎么转换字符串形式,下标不要搞错
题意:从第四项开始,每一项是前3项的和,求该项的后四位数字
1.定义一个比求得项数大的数组,然后运用循环来对每一项求值
2.在计算该项的时候,取该项后四位数,到达指定项就结束。
3. 注意:累加会爆
#include
#include
#include
using namespace std;
int a[20190334] = {0,1,1,1};
int main(){
int res = 0;
for(int i = 4; i <= 20190324; i ++ ){
a[i] = (a[i - 1] + a[i - 2] + a[i - 3])%10000;
}
cout<
总结:要定义一个大点的数组,不能就定义a[4]的数组进行循环,那样就是在原地踏步。
题意:把2019分解为三个不同的正整数,它们都不包含2或者4
注意:1000+1001+18 和1001 + 1000 +18 是同一种方法
#include
#include
#include
using namespace std;
bool judge(int n) {
do {
if(n % 10 == 2 || n % 10 == 4) {
return false;
}
n /= 10;
} while(n != 0);
return true;
}
int main() {
int res = 0;
for(int a = 1; a <= 2019; a ++ ) {
if(judge(a)) {
for(int b = a + 1; b <= 2019; b ++ ) {
if(judge(b)) {
for(int c = b + 1; c <= 2019; c ++ ) {
if(judge(c)){
if(a + b + c == 2019) res ++;
}
}
}
}
}
}
cout<
总结:这种方法就是费时间(好几秒),但是非常适合题中条件
01010101001011001001010110010110100100001000101010
00001000100000101010010000100000001001100110100101
01111011010010001000001101001011100011000000010000
01000000001010100011010000101000001010101011001011
00011111000000101000010010100010100000101100000000
11001000110101000010101100011010011010101011110111
00011011010101001001001010000001000101001110000000
10100000101000100110101010111110011000010000111010
00111000001010100001100010000001000101001100001001
11000110100001110010001001010101010101010001101000
00010000100100000101001010101110100010101010000101
11100100101001001000010000010101010100100100010100
00000010000000101011001111010001100000101010100011
10101010011100001000011000010110011110110100001000
10101010100001101010100101000010100000111011101001
10000000101100010000101100101101001011100000000100
10101001000000010100100001000100000100011110101001
00101001010101101001010100011010101101110000110101
11001010000100001100000010100101000001000111000010
00001000110000110101101000000100101001001000011101
10100101000101000000001110110010110101101010100001
00101000010000110101010000100010001001000100010101
10100001000110010001000010101001010101011111010010
00000100101000000110010100101001000001000000000010
11010000001001110111001001000011101001011011101000
00000110100010001000100000001000011101000000110011
10101000101000100010001111100010101001010000001000
10000010100101001010110000000100101010001011101000
00111100001000010000000110111000000001000000001011
10000001100111010111010001000110111010101101111000
【答案提交】
这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一
个字符串,包含四种字母 D、U、L、R,在提交答案时只填写这个字符串,填
写多余的内容将无法得分。
题意:水题
#include
#include
#include
using namespace std;
int n;
int res;
bool judge(int n){
do{
int t = n % 10;
if(t == 0 || t == 1 || t == 2 || t == 9) return true;
n /= 10;
}while(n != 0);
return false;
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i ++ ){
if(judge(i)) res += i;
}
printf("%d\n",res);
return 0;
}
7
1 6 5 4 3 2 1
2
【评测用例规模与约定】
对于所有评测用例,1 ≤ N ≤ 100000,ˈ 100000 ≤ Ai ≤ 100000。
题意:求二叉树上最大的一层的节点之和,输出该层数
#include
#include
#include
#include
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N = 1e5 + 10;
int n;
int a[N];
ll ans = -inf;
int cnt,dep = 1,depth = 1;
int main() {
scanf("%d",&n);
for(int i = 1; i <= n; i ++ ){
scanf("%d",&a[i]);
}
for(int i = 1; i <= n; i *= 2){
ll sum = 0;
for(int j = i; j <= 2 * i - 1 && j <= n; j ++ ){
sum += a[j];
}
if(sum > ans){
ans = sum;
dep = depth;
}
depth ++;
}
cout<
题意:给你一列数字,求这一列数字排列成最短等差数列
注意:这里d可能为0,这就要输出n个项
d不为0,输出(a[n] - a[1] / d + 1 )个项
#include
#include
#include
#include
#include
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N = 1e5 + 10;
int n,d;
int a[N];
int gcd(int a,int b){
return b ? gcd(b,a%b) : a;
}
int main() {
scanf("%d",&n);
for(int i = 1; i <= n; i ++ ){
scanf("%d",&a[i]);
}
sort(a + 1, a + n + 1);
for(int i = 1; i <= n-1; i ++ ){
d = gcd(a[i + 1] - a[i], d);
}
int ans = 0;
if(d == 0) ans = n;
else ans = (a[n] - a[1]) / d + 1;
printf("%d",ans);
return 0;
}
题意:后缀表达式:在中缀的基础上,可以随便加上括号
注意:数组不要开成1e5,因为总共大小是n + m + 1 ,开2e5 + 10
定义long long 型变量,防止爆int
#include
#include
#include
#include
#include
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N = 2e5 + 10;
int n,m,k;
ll a[N];
int main() {
scanf("%d %d",&n,&m);
k = n + m + 1;
ll sum = 0;
for(int i = 1; i <= k; i ++ ) {
scanf("%lld",&a[i]);
}
sort(a + 1, a + k + 1);
if(m == 0){
for(int i = 1; i <= k; i ++ ) sum += a[i];
printf("%lld",sum);
return 0;
}
sum += a[k], sum -= a[1], m --;
for(int i = 2; i < k; i ++ ){
sum += abs(a[i]);
}
printf("%lld",sum);
return 0;
}