CF 183(div2)

B.直接一天天加上去。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define LL long long
using namespace std;

int fromy,fromm,fromd,toy,tom,tod;
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

bool isleap(int x){
    if(x%400 == 0 || (x%4 == 0 && x%100)) return true;
    return false;
}

int main(){
    while(scanf("%d:%d:%d",&fromy,&fromm,&fromd) != EOF){
        scanf("%d:%d:%d",&toy,&tom,&tod);
        if(toy < fromy || toy == fromy && tom < fromm || toy == fromy && tom == fromm && tod < tom){
            swap(fromy,toy); swap(fromd,tod); swap(fromm,tom);
        }
        int ans = 0;
        int y = fromy,m = fromm,d = fromd;
        while(y != toy || m != tom || d != tod){
            ans++;
            int total = month[m];
            if(m == 2 && isleap(y)) total++;
            if(d+1 > total){ d = 1; m++; }
            else d++;
            if(m > 12){ m = 1; y++; }
        }
        printf("%d\n",ans);
    }
    return 0;
}


C.找规律,貌似有很多种规律,随便找到一种就可以了,我是直接套的样例的那种规律。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define LL long long
using namespace std;
const int maxn = 100000 + 5;

int a[maxn],b[maxn],c[maxn];

int main(){
    int n;
    while(scanf("%d",&n) != EOF){
        if(n%2 == 0){
            printf("-1\n");
            continue;
        }
        for(int i = 0;i < n;i++) c[i] = i;
        for(int i = 0;i < n-1;i++) a[i] = n-2-i;a[n-1] = n-1;
        for(int i = 0;i < n;i++){
            b[i] = (n+c[i]-a[i])%n;
        }
        for(int i = 0;i < n;i++) printf("%d ",a[i]);cout << endl;
        for(int i = 0;i < n;i++) printf("%d ",b[i]);cout << endl;
        for(int i = 0;i < n;i++) printf("%d ",c[i]);cout << endl;
    }
    return 0;
}

 


D.yy乱搞题,就是要注意点不能超过上界和下界,缺一不可。开始在找矩形的长宽时是直接判断宽从大到小对应的长是不是整数,这样做wa的蛮惨,精度问题很难把握,后来改成先除gcd的做法就直接过了。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define LL long long
using namespace std;
const int maxn = 100000 + 5;

int gcd(int a,int b){
    return b == 0?a:gcd(b,a%b);
}

int main(){
    int n,m,x,y,a,b,lenx,leny;
    int ansx1,ansy1,ansx2,ansy2;
    while(scanf("%d%d%d%d%d%d",&n,&m,&x,&y,&a,&b) != EOF){
        int tem = gcd(a,b);
        a = a/tem;b = b/tem;
        for(int i = 1;;i++){
            if(a * i <= n && b*i <= m){
                lenx = a*i;
                leny = b*i;
            }
            else break;
        }
        if(lenx % 2 == 0) ansx1 = max(0,x-lenx/2);
        else ansx1 = max(0,x-(lenx/2+1));
        ansx2 = ansx1+lenx;
        if(ansx2 > n) {
            ansx2 = n;
            ansx1 = n-lenx;
        }
        if(leny % 2 == 0) ansy1 = max(0,y-leny/2);
        else ansy1 = max(0,y-(leny/2+1));
        ansy2 = ansy1 + leny;
        if(ansy2 > m){
            ansy2 = m;
            ansy1 = m - leny;
        }
        printf("%d %d %d %d\n",ansx1,ansy1,ansx2,ansy2);
    }
    return 0;
}


E.数学题不会做。

你可能感兴趣的:(CF 183(div2))