1. 程式人生 > >暑假第十二測

暑假第十二測

2-0 info hid memset fc7 add bits stdout 自己

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

題解:第一題:

打表找規律,從12以後每次加49,我一直在前十找規律,,找了半天,以後還是多打點,學聰明點

技術分享圖片
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int zl[4] = {1,5,10,50};
ll ans[] = {0,4,10,20,35,56,83,116,155,198,244,292,341,390,439,488,537,586,635,684,733,782,831,880,929,978,1027,1076,1125,1174,1223,1272,1321,1370,1419
,1468,1517,1566,1615,1664,1713,1762,1811,1860,1909,1958,2007,2056,2105,2154,2203,2252,2301,2350,2399,2448,2497,2546,2595,2644,2693,2742,2791,2840,2889,2938,2987,3036,3085,3134,3183,3232,3281,3330,3379,3428,3477,3526,3575,3624,3673,3722,3771,3820,3869,3918,3967,4016,4065,4114,4163,4212,4261,4310,4359,4408,4457,4506,4555
,4604,4653}; int Ans = 0; int main() { freopen("a.in","r",stdin); freopen("a.out","w",stdout); ll n; scanf("%I64d", &n); if(n <= 12)printf("%I64d\n", ans[n]); else printf("%I64d\n", 49* (n - 12) + ans[12]); }
View Code

第二題:

這是一道傻逼題,但我就是沒想出來,利用log單增函數就好了,比較log2 x^y. log2 y^x ‘即 ylog2x xlog2y

技術分享圖片
#include <bits/stdc++.h>
using namespace std;

int main()
{
    freopen("b.in","r",stdin);
    freopen("b.out","w",stdout);
    int T;
    scanf("%d", &T);
    while(T--){
        double a, b;
        scanf("%lf%lf", &a, &b);
           if(a == b){puts("=");continue;}
           if(a == 1 && b > 1){puts("<");continue;}
        if(b == 1 && a > 1){puts(">");continue;}
        if(a*log(b) > b*log(a)){puts("<");continue;}
        if(a*log(b) < b*log(a)){puts(">");continue;}
        puts("=");
        //printf("%d\n", work(a, b, x, y, aa, bb));
   }
    return 0;
}
View Code

第三題:

這道題最開始看著像上司的舞會,但簡單畫畫圖就知道會成環,然後就二分圖匹配,原題是bzoj數字匹配,把數按質因子個數奇偶拆成兩組,最大點獨立集

技術分享圖片
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M = 500005;
int a[M], tmp[M];
bool check(int a, int b){
    if(a > b)swap(a, b);
    if(b%a)return 0;
    int d = b/a;
    for(int i = 2; i <= d; i++){
        if(d%i == 0 && d != i)return 0;
    }
    return 1;    
}
struct {int id, val;}odd[M], even[M];
int h[M], match[M], tot, cnt, t2, t1;
bool vis[M];
struct edge{int v,nxt;}G[M<<1];
void add(int u, int v){G[++tot].nxt=h[u]; h[u]=tot; G[tot].v=v;}
void init(){
    memset(h, 0, sizeof(h));
    memset(match, 0, sizeof(match));
    tot = cnt = t1= t2 = 0;
    
}

bool find(int u){
    for(int i = h[u]; i; i = G[i].nxt){
        int v = G[i].v;
        if(vis[v])continue;
        vis[v] = 1;
        if(!match[v] || find(match[v])){
            match[v] = u;
            return 1;
        }
    }
    return 0;
}

int main()
{
    freopen("c.in","r",stdin);
    freopen("c.out","w",stdout);
    int T;
    scanf("%d", &T);
    while(T--){
        int n, ans = 0, cur = 0;
        scanf("%d", &n);
        init();
        for(int i = 1; i <= n; i++){
            scanf("%d", &a[i]);
            int tt = a[i];
            int cnt = 0;
            for(int j = 2; j <= a[i]; j++)
                if(a[i]%j == 0){
                    while(a[i]%j == 0) a[i] /= j, cnt++;
                }
            if(cnt & 1) odd[++t1].val = tt, odd[t1].id = ++cur;
            else even[++t2].val = tt, even[t2].id = ++cur;
        }
        for(int i = 1; i <= t1; i++)
            for(int j = 1; j <= t2; j++)
                if(check(odd[i].val, even[j].val))add(odd[i].id, even[j].id);
        for(int i = 1; i <= t1; i++){
            memset(vis, 0, sizeof(vis));
            if(find(odd[i].id)) ans++;
        }
            
        printf("%d\n", n - ans);
        
   }
    return 0;
}
View Code 早上洛谷說忌模擬賽,結果真的倒數,而且今天題挺水的,自己太菜了

暑假第十二測