1. 程式人生 > >九度oj 專題整理 (模擬部分1)

九度oj 專題整理 (模擬部分1)

分類參考連結    點選開啟連結

假期陸續刷了很多水題,覺得ACM只要能理解思路的程式碼都是水題,套路也是有的,不過我的水平也就停留在水題上了,隨著面試日期的臨近,反而今天有些不靜心,就不如現在整理一下自己做過的水題吧,也免得眼高手低,現在看看自己當時寫的程式碼,很多思路也讓現在的自己吃驚。因為自己總是喜歡倒序做事,那就從每個專題的題目倒序來吧

模擬型別:1000 1001 1020 1031 1036 1038 1013 1014 1045 1046 1048 1050 1059 1060 1062 1063 1064 1065 1067 1068 1070 1075  1177 1179 1183 1186

題目:1186(簡單來說,就是判斷閏年)因為之前做過類似的題目,這個就不再寫一遍了

題目 1 Maya Calendar 點選開啟連結

題目2 列印月曆 點選開啟連結

1.Maya Calendar,這個題目如果先加上1,再去對月份和星期取餘,換過各種方式,樣例過了,卻總WA,現在還不懂為什麼,所以參照網上的,改成先取餘後加了,

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#define LL long long
#define PI acos(-1)
#define exp 1e-9
using namespace std;
priority_queue <int, vector<int>, greater<int> > Q;
char Haab[20][20]={"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan","pax", "koyab", "cumhu", "uayet"};
char holly[20][20]={"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};
int main()
{
    //printf("%s",Haab[1]);
    int n;
    scanf("%d",&n);
    //printf("%d\n",n);
    int day,year;
    char month[10];
    int sum[10000];
    memset(sum,0,sizeof(sum));
    for(int j=0; j<n; j++)
    {
        scanf("%d.%s %d",&day,month,&year);
        sum[j]+=year*365;
        for(int i=0; i<19; i++)
        {
            if(strcmp(Haab[i],month)==0)
            {
                sum[j]+=i*20;
                break;
            }
        }
        sum[j]+=day;
        //printf("%d.%s %d",day,month,year);
    }
    printf("%d\n",n);
    //printf("%.8lf\n",16/10);
    for(int k=0; k<n; k++)
    {
        int y=sum[k]/260;
        //printf("%d\n",sum[k]);
        int m=sum[k]%20;
        int d=sum[k]%13+1;
        printf("%d %s %d\n",d,holly[m],y);
    }
    return 0;
 }

2.列印月曆

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define exp 1e-6
#define pi acos(-1.0)
using namespace std;
int m1[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int m2[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};

bool judge(int year)
{
    if(year%100==0)
    {
        if(year%400==0)
        {
            return true;
        }
    }
    else
    {
        if(year%4==0)
        {
            return true;
        }
    }
    return false;
}
int daynum(int year)
{
    int day=0;
    for(int i=1900; i<year; i++)
    {
        if(judge(i))
        {
            day+=366;
        }
        else
        {
            day+=365;
        }
    }
    return day;
}
int monthday(int year,int month)
{
    int mday=0;
    if(judge(year))
    {
        for(int i=0; i<month; i++)
        {
            mday+=m2[i];
        }
    }
    else
    {
        for(int i=0; i<month; i++)
        {
            mday+=m1[i];
        }
    }
    return mday;
}
int main()
{
    int year,month;
    while(~scanf("%d %d",&year,&month))
    {
        int day=daynum(year);
        day+=monthday(year,month);
        printf("Sun Mon Tue Wed Thu Fri Sat\n");
        int flag=0;
        int mod=day%7+1;
        for(int k=0; k<mod; k++)
        {
            printf("    ");
            flag++;
        }
        if(judge(year))
        {
            for(int i=1; i<m2[month];i++)
            {
                printf("%3d ",i);
                flag++;
                if(flag%7==0)
                printf("\n");
            }
            printf("%3d\n",m2[month]);
        }
        else
        {
            for(int i=1; i<m1[month];i++)
            {
                printf("%3d ",i);
                flag++;
                if(flag%7==0)
                printf("\n");
            }
            printf("%3d\n",m1[month]);
        }

       // printf("%d\n",day%7);
    }
    return 0;
}

題目1183:守形數

現在看上去的想法還可以,大概是鑽了數很小的空子,不然別的思路呢?

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#define LL long long
#define PI acos(-1)
#define exp 1e-9
using namespace std;
priority_queue <int, vector<int>, greater<int> > Q;
 
 
int main()
{
    int n,m,ans;
    while(~scanf("%d",&n))
    {
        m=n*n;
        if(n<10)
            ans=m%10;
        else if(n<100)
            ans=m%100;
        else
            ans=m%1000;
        if(ans==n)
            printf("Yes!\n");
        else
            printf("No!\n");
    }
    return 0;
 }
 

題目1179:階乘,

題目很簡單,可能對於初學者來說,就是要注意階乘資料型別要用long long 吧,還做過一個題目要用double,發現自己之前wa過兩次,原來將n%2判斷奇數偶數寫成了n%1 = =

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#define LL long long
#define PI acos(-1)
#define exp 1e-9
#define INF 0x7fffffff
using namespace std;
priority_queue <int, vector<int>, greater<int> > Q;
long long list[1010];
int n;
int fun()
{
    list[0]=1;
    for(int i=1; i<=n; i++)
    {
        list[i]=list[i-1]*i;
        //printf("%d\n",list[i]);
    }
 
}
int main()
{
    while(~scanf("%d",&n))
    {
        fun();
        LL ans=0,cnt=0;
        if(n%2)
        {
            for(int i=1; i<=n; i+=2)
            {
                ans+=list[i];
            }
            for(int i=2; i<=n-1; i+=2)
            {
                cnt+=list[i];
            }
        }
        else
        {
            for(int i=1; i<=n-1; i+=2)
            {
                ans+=list[i];
            }
            for(int i=2; i<=n; i+=2)
            {
                cnt+=list[i];
            }
        }
        printf("%lld %lld\n",ans,cnt);
    }
    return 0;
}

太長了,三個題為單位續寫吧,,