2017年中南大学机试题(坑人oj)

题目链接链接

(帮学长研究一下机试题)

A 木棍,注意不能是正方形;

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
const int maxn = 1e5+50;
const int inf = 0x3f3f3f3f;
int n;
int main()
{

    while(~scanf("%d",&n))
    {
       long long ans = 0;
       if(n%2!=0)
       {
           printf("0\n");
       }
       else
       {
           if(n%4==0)
              printf("%d\n",n/4-1);
           else
              printf("%d\n",n/4);
       }
    }

   //    cout << "Hello world!" << endl;
    return 0;
}

B题

wa了n次,这个中南大学的oj太傻逼了!!! 输入输出很有问题,做了这么多年oj,第一次发现scanf没有返回值会导致错误的。

无力吐槽了,代码从一开始就是对的!我服了。

第一次一道简单模拟题我做了一个半小时,我都开始怀疑人生了。

幸好我没放弃,帮学长踩出坑来了,注意输入输出。而且后来用getchar()的时候也会出现诡异的错误。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
const int maxn = 50;
const int inf = 0x3f3f3f3f;
int w,h;
char mp[maxn][maxn];
int dx[]= {-1,0,1,0};
int dy[]= {0,1,0,-1};
int vis[maxn][maxn];
int oj(int x,int y)
{
    if(x>=0 && x=0 && y

C 一开始看错了题意,后来发现是个简单dp,求每行最大值,然后再求列最大值就是答案

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
 
using namespace std;
const int maxn = 2e2+50;
const int inf = 0x3f3f3f3f;
int w,h;
int s[maxn][maxn];
int dx[]= {-1,0,1,0};
int dy[]= {0,1,0,-1};
int vis[maxn][maxn];
int dp[maxn][2];
int cnt[maxn];
int main()
{
    while(scanf("%d%d",&w,&h)==2)
    {
        for(int i=1; i<=w; i++)
            for(int j=1; j<=h;j++)
              scanf("%d",&s[i][j]);
        for(int i=1; i<=w; i++)
        {
            memset(dp,0,sizeof(dp));
            for(int j=1; j<=h; j++)
            {
                dp[j][0] = max(dp[j-1][0],dp[j-1][1]);
                dp[j][1] = dp[j-1][0]+s[i][j];
            }
            cnt[i] = max(dp[h][0],dp[h][1]);
            //cout<

D 很常见的一个贪心加二分,其实方法就是求最长上升子序列

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
 
using namespace std;
const int maxn = 1e5+50;
const int inf = 0x3f3f3f3f;
int w,h;
int s[maxn];
int dx[]= {-1,0,1,0};
int dy[]= {0,1,0,-1};
 
int cnt[maxn];
int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        memset(cnt,inf,sizeof(cnt));
        for(int i=0; i"<

E.我先睡会,以前做过类似的(HDU 2717) (别人的代码)

#include
#include
#include
#include
#include
#include
#include
#define MAX 100010
using namespace std;
int n,k;
int  cur,nextt;
int step[MAX];
queueq;
void bfs()
{
    while(!q.empty())
    {
        cur=q.front();
        q.pop();
        if(cur==k)  break;
        nextt=cur-1;
        if(nextt>=0&&step[nextt]==0)
        {
            q.push(nextt);
            step[nextt]=step[cur]+1;
        }
        nextt=cur+1;
        if(step[nextt]==0)
        {
            q.push(nextt);
            step[nextt]=step[cur]+1;
        }
        nextt=cur*2;
        if(nextt<=100000&&(nextt-k)<(k-cur)&&step[nextt]==0)
        {
            q.push(nextt);
            step[nextt]=step[cur]+1;
        }
    }
 
}
int main()
{
    while(scanf("%d%d",&n,&k)==2)
    {
        memset(step,0,sizeof(step));
        if(n>k)
            cout<<(n-k)<

 

你可能感兴趣的:(杂记)