JNday1-am

T1 10 ^ 8 都可以过

不过T2没有用心推公式,推出(一个并不难)公式,p为素数

x^3 - y^3

(x - y) * (x - y) ^ 2

(x - y) * (x ^ 2 - 2 * x * y - y ^ 2)

因为p是一个素数

(x - y) = 1;

y = x - 1;

代入, 暴力

T3, 乱搞错了

 

立方数(cubic)

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

#define LL long long

inline LL read()
{
    LL x = 0; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x;
}

int T;

int main()
{
    freopen("cubic.in","r",stdin);
    freopen("cubic.out","w",stdout);
    scanf("%d", &T);
    while(T --)
    {
        LL p = read();
        for(int i = 1; ; i ++)
        {
            LL ii = i;
            LL imp = ii * ii * ii;
            if(imp == p)
            {
                printf("YES\n"); 
                break;
            }
            else if(imp > p)
            {
                printf("NO\n"); 
                break;
            }
        }
    }    
    return 0;
}

 

立方数2(cubicp)

//30#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

#define LL long long

using namespace std;

int T;

inline LL read()
{
    LL x = 0; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x;
}

int main()
{
    freopen("cubicp.in","r",stdin);
    freopen("cubicp.out","w",stdout);
    scanf("%d", &T);
    while(T --)
    {
        LL p = read();
        bool flag = 1;
        for(int i = 0; flag && i <= 500; i ++)
            for(int j = i; flag && j <= 500; j ++)
            {
                LL ii = i, jj = j;
                LL cha = jj * jj * jj - ii * ii * ii;
                if(cha == p)
                {
                    printf("YES\n");
                    flag = 0;
                }
                if(cha > p) break;
            }
        if(flag) printf("NO\n");
    }
    
    return 0;
}
//std
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#include<string>
using namespace std;
int main()
{
    freopen("cubicp.in","r",stdin);
    freopen("cubicp.out","w",stdout);
    int t,flag;
    scanf("%d",&t);
    long long p;
    while(t--)
    {
        flag=0;
        scanf("%I64d",&p);
        for(int i=1;i<=1e6+10;i++)
        {
            if(3ll*i*i+3*i+1==p)
            {
                flag=1;
                break;
            }
            if (3ll*i*i+3*i+1>p) break;
        }
        if(flag) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

 

猜数字(number)

//20
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;
const int N = 5e4 + 10;

struct Node{
    int l, r, minn;
}E[N];

int vis[10];

inline int read()
{
    int x = 0; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x;
}

int n, T;

int main()
{
    freopen("number.in","r",stdin);
    freopen("number.out","w",stdout);
    n = read();
    T = read();
    E[1].l = read();
    E[1].r = read();
    E[1].minn = read();
    for(int i = E[1].l; i <= E[1].r; i ++) vis[i] = 1;
    for(int i = 2; i <= T; i ++)
    {
        E[i].l = read();
        E[i].r = read();
        E[i].minn = read();
        int kong = 0;
        int min_min = 99999999;
        for(int j = E[i].l; j <= E[i].r; j ++)
        {
            if(!vis[j]) kong ++;
            else min_min = min(min_min, E[vis[j]].minn);
        }
        if(kong == 0)
        {
            if(E[i].minn != min_min)
            {
                printf("%d", i);
                return 0;
            }
        }
    }
    printf("%d", T + 1);
    return 0;
}
//std
#include <cstdio>
#include <iostream>
#include <algorithm>
#define N 1000011
#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y))
using namespace std;
int n, q, ans;
int f[N];

struct node
{
    int x, y, z;
}p[N], t[N];

inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
    return x * f;
}

inline bool cmp(node x, node y)
{
    return x.z > y.z;
}

inline int find(int x)
{
    return x == f[x] ? x : f[x] = find(f[x]);
}

inline bool check(int k)
{
    int i, j, x, y, lmin, lmax, rmin, rmax;
    for(i = 1; i <= n + 1; i++) f[i] = i;
    for(i = 1; i <= k; i++) t[i] = p[i];
    std::sort(t + 1, t + k + 1, cmp);
    lmin = lmax = t[1].x;
    rmin = rmax = t[1].y;
    for(i = 2; i <= k; i++)
    {
        if(t[i].z < t[i - 1].z)
        {
            if(find(lmax) > rmin) return 1;
            for(j = find(lmin); j <= rmax; j++)
                f[find(j)] = find(rmax + 1);
            lmin = lmax = t[i].x;
            rmin = rmax = t[i].y;
        }
        else
        {
            lmin = min(lmin, t[i].x);
            lmax = max(lmax, t[i].x);
            rmin = min(rmin, t[i].y);
            rmax = max(rmax, t[i].y);
            if(lmax > rmin) return 1;
        }
    }
//    cout<<find(1)<<endl;
    if(find(lmax) > rmin) return 1;
    return 0;
}

int main()
{
    freopen("number.in","r",stdin);
    freopen("number.out","w",stdout);
    int i, x, y, mid;
    n = read();
    q = read();
    for(i = 1; i <= q; i++)
        p[i].x = read(), p[i].y = read(), p[i].z = read();
    x = 1, y = q;
    //cout<<check(2)<<endl;
    //return 0;
    ans = q + 1;
    while(x <= y)
    {
        mid = (x + y) >> 1;
        if(check(mid)) ans = mid, y = mid - 1;
        else x = mid + 1;
    }
    printf("%d\n", ans);
    return 0;
}

 

posted @ 2017-10-28 20:23  ioioioioioio  阅读(148)  评论(0编辑  收藏  举报