#include<bits/stdc++.h>
using namespace std;intmain(){freopen("data.in","r",stdin);freopen("power.out","w",stdout);int n;
cin >> n;if(n %2==1) cout <<-1<< endl;else{while(n){int t =pow(2,(int)log2(n));
cout << t <<' ';
n -= t;}
cout << endl;}return0;}
代码2
#include<bits/stdc++.h>
using namespace std;intmain(){freopen("data.in","r",stdin);freopen("power2.out","w",stdout);int n;
cin >> n;if(n &1==1) cout <<-1<< endl;else{for(int i =30; i >=0; i --){if(n >> i &1){
cout <<(1<< i)<<' ';}}
cout << endl;}return0;}
生成随机数据
#include<bits/stdc++.h>
using namespace std;intmyrand(){return(rand()<<16)+(rand()<<1)+(rand()&1);}intmain(){freopen("data.in","w",stdout);srand(time(0));int n =myrand();
cout << n << endl;return0;}
对拍
@echo off
:loop
make_data
echo ~~~~
echo 输入
type data.in
echo ~~~~
power
power2
fc power.out power2.out
if errorlevel ==1 pause
goto loop
T2 直播获奖
代码1
#include<bits/stdc++.h>
using namespace std;int n, w, x, ttl, cnt[610];intmain(){freopen("data.in","r",stdin);freopen("live.out","w",stdout);scanf("%d%d",&n,&w);for(int i =1;i <= n;i ++){scanf("%d",&x);
cnt[x]++;
ttl =max(1, i*w/100);for(int j =600; j >=0; j --){
ttl -= cnt[j];if(ttl <=0){printf("%d ", j);break;}}}return0;}
代码2
#include<bits/stdc++.h>
using namespace std;int n, w, x, ttl;
priority_queue <int, vector<int>, greater<int>> l;//其它元素大于top -> 小根堆
priority_queue <int, vector<int>, less<int>> r;//其它元素小于top -> 大根堆,默认是大根堆/*
l r
400
500 300
600 200
*/intmain(){freopen("data.in","r",stdin);freopen("live2.out","w",stdout);scanf("%d%d",&n,&w);for(int i =1; i <= n; i ++){scanf("%d",&x);if(l.empty()|| x > l.top()){
l.push(x);}else{
r.push(x);}
ttl =max(1, i*w/100);while(l.size()> ttl){
r.push(l.top());
l.pop();}while(l.size()< ttl){
l.push(r.top());
r.pop();}printf("%d ", l.top());}return0;}
生成随机数据
#include<bits/stdc++.h>
using namespace std;intmyrand(){return(rand()<<16)+(rand()<<1)+(rand()&1);}intmain(){freopen("data.in","w",stdout);srand(time(0));int n =myrand()%100000+1;int w =myrand()%99+1;printf("%d %d\n", n, w);for(int i =1; i <= n; i ++){int score =myrand()%601;printf("%d ", score);}return0;}
对拍
@echo off
:loop
make_data
live
live2
fc live.out live2.out
if errorlevel == 1 pause
goto loop
T4 方格取数
代码1:深搜 25分
#include<bits/stdc++.h>#defineLLlonglong
using namespace std;constint N =1e3+10;int n, m;
LL ans =-1e18, a[N][N];
bool vst[N][N];int dx[3]={-1,0,1};int dy[3]={0,1,0};voiddfs(int x,int y, LL num){if(x == n && y == m){
ans =max(ans, num);return;}for(int i =0; i <3; i ++){int xx = x + dx[i];int yy = y + dy[i];if(xx <1|| xx > n || yy > m)continue;if(vst[xx][yy])continue;
vst[xx][yy]= true;dfs(xx, yy, num + a[xx][yy]);
vst[xx][yy]= false;}}intmain(){scanf("%d%d",&n,&m);for(int i =1; i <= n; i ++){for(int j =1; j <= m; j ++){scanf("%lld",&a[i][j]);}}
vst[1][1]= true;dfs(1,1, a[1][1]);printf("%lld\n", ans);return0;}
代码2:深搜 + 剪枝40分
#include<bits/stdc++.h>#defineLLlonglong
using namespace std;constint N =1010;int n, m;
LL ans =-1e18, a[N][N], s[N][N][3];
bool vst[N][N];int dx[3]={-1,0,1};int dy[3]={0,1,0};voiddfs(int x,int y, LL num){if(x == n && y == m){
ans =max(ans, num);return;}for(int i =0; i <3; i ++){int xx = x + dx[i];int yy = y + dy[i];if(xx <1|| xx > n || yy > m)continue;if(vst[xx][yy])continue;if(num + a[xx][yy]<= s[xx][yy][i])continue;
s[xx][yy][i]= num + a[xx][yy];
vst[xx][yy]= true;dfs(xx, yy, num + a[xx][yy]);
vst[xx][yy]= false;}}intmain(){scanf("%d%d",&n,&m);for(int i =1; i <= n; i ++){for(int j =1; j <= m; j ++){scanf("%lld",&a[i][j]);for(int k =0; k <3; k ++){
s[i][j][k]=-1e18;}}}
vst[1][1]= true;dfs(1,1, a[1][1]);printf("%lld\n", ans);return0;}
代码3:动态规划100分
#include<bits/stdc++.h>#defineLLlonglong
using namespace std;constint N =1e3+10;int n, m, a[N][N];
LL dp[N][N][2];//dp[i][j][0]表示从左边或上面走过来的路径的最大值//dp[i][j][1]表示从左边或下面走过来的路径的最大值
LL myMax(LL a, LL b, LL c){returnmax(a,max(b, c));}intmain(){
cin >> n >> m;for(int i =1; i <= n; i ++)for(int j =1; j <= m; j ++) cin >> a[i][j];memset(dp,-0x3f,sizeof(dp));
dp[1][0][0]=0;for(int j =1; j <= m; j ++){for(int i =1; i <= n; i ++){
dp[i][j][0]=myMax(dp[i-1][j][0], dp[i][j-1][0], dp[i][j-1][1])+ a[i][j];}for(int i = n; i >=1; i --){
dp[i][j][1]=myMax(dp[i+1][j][1], dp[i][j-1][0], dp[i][j-1][1])+ a[i][j];}}
cout << dp[n][m][0]<< endl;return0;}
生成随机数据
#include<bits/stdc++.h>
using namespace std;intmyrand(){return(rand()<<16)+(rand()<<1)+(rand()&1);}intmain(){freopen("data.in","w",stdout);srand(time(0));int n =myrand()%50+1;int m =myrand()%50+1;printf("%d %d\n", n, m);for(int i =1; i <= n; i ++){for(int j =1; j <= m; j ++){int x =myrand()%20001-10000;printf("%d ", x);}printf("\n");}return0;}