28. 马鞍点
#include<bits/stdc++.h>
using namespace std;
int main() {
int m,n,num;
cin>>m>>n;
int a[m][n];
int rowMin[m];
int colMax[n];
for(int i=0;i<m;++i){
for(int j=0;j<n;++j){
cin>>num;
a[i][j]=num;
if(i==0||num>colMax[j]){
colMax[j]=num;
}
if(j==0||num<rowMin[i]){
rowMin[i]=num;
}
}
}
for(int i=0;i<m;++i){
for(int j=0;j<n;++j){
if(a[i][j]==rowMin[i]&&a[i][j]==colMax[j]){
cout<<i+1<<" "<<j+1<<" "<<a[i][j]<<endl;
}
}
}
return 0;
}
29. 完美数
#include<bits/stdc++.h>
using namespace std;
int temp[15]={1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384};
int main() {
vector<int> nums;
for(int i=2;i<=10000;++i){
vector<int> yinzi;
for(int j=1;j<i;++j){
if(i%j==0){
yinzi.push_back(j);
}
}
int sum=0;
for(int k=0;k<yinzi.size();++k){
sum+=yinzi[k];
}
if(sum==i){
cout<<i<<" ";
nums.push_back(i);
}
}
cout<<endl;
for(int i=0;i<nums.size();++i){
for(int j=0;j<15;++j){
if(nums[i]*2==(temp[j]-1)*temp[j]){
cout<<nums[i]<<" "<<j<<endl;
break;
}
}
}
return 0;
}
30. 机器人
#include<iostream>
#include<vector>
using namespace std;
int N;
int a[7]={0,1,1,1,1};
int b[7]={0,0,1,2,3};
vector<int> f1(a,a+5);
vector<int> f2(b,b+5);
int main(){
cin>>N;
for(int i=5;i<=N;++i){
f1.push_back(f1[i-1]+f2[i-3]);
f2[i-1]-=f2[i-3];
f2[i-2]-=f2[i-3];
f2.push_back(f2[i-1]+f1[i]);
}
cout<<f1[N]+f2[N];
return 0;
}