头像

ZJ_cao


访客:2688

离线:15小时前


活动打卡代码 AcWing 1205. 买不到的数目

ZJ_cao
1天前
#include <iostream>

using namespace std;

int main ()
{
    int n,m;
    cin>>n>>m;
    cout<<(n-1)*(m-1)-1;
    return 0;
}


活动打卡代码 AcWing 1221. 四平方和

ZJ_cao
3天前
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int N=5000010;
struct
{
    int c1,d1;
    int flag;
}h[N];
int n;

int main()
{
    cin>>n;
    int a,b,c,d;
    for(c=0;c*c<=n;c++)
    {
        for(d=c;d*d<=n-c*c;d++)
        {
           if(h[c*c+d*d].flag==0)
           {
               h[c*c+d*d].c1=c;
               h[c*c+d*d].d1=d;
               h[c*c+d*d].flag=1;
           }
        }
    }

    for(a=0;a*a<=n;a++)
    {
        for(b=a;b*b<=n-a*a;b++)
        {
            int t=n-a*a-b*b;
            if(h[t].flag==1)
            {
                printf("%d %d %d %d\n",a,b,h[t].c1,h[t].d1);
                return 0;
            }
        }
    }
    return 0;
}



ZJ_cao
3天前
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 1e5+10;
int n;
int a[N];

int main ()
{
    scanf("%d",&n);
    int INF = -1e9;
    for (int i = 0 ; i < n ; i++)
    {
        scanf("%d",&a[i]);
        INF = max(INF,a[i]);
    }

    int l = 0,r = INF;
    while(l<=r)
    {
        int mid = (l+r)>>1;
        long long res = mid;
        for (int i = 0 ; i < n ; i++)
        {
            res+=res-a[i];
            if (res<0)
            {
                l=mid+1;
                break;
            }
            if (res>=INF)
            {
                r=mid-1;
                break;
            }
        }
    }

    cout<<l<<endl;
    return 0;
}


活动打卡代码 AcWing 796. 子矩阵的和

ZJ_cao
3天前
#include <cstdio>

int n,m,q;
int a[1010][1010],s[1010][1010];

int main ()
{
    scanf("%d%d%d",&n,&m,&q);

    for (int i = 1 ; i <= n ; i++)
        for (int j = 1 ; j <= m ; j++)
            scanf("%d",&a[i][j]);

    for (int i = 1 ; i <= n ; i++)
        for (int j = 1 ; j <= m ; j++)
            s[i][j] = a[i][j]+s[i-1][j]+s[i][j-1]-s[i-1][j-1];

    while (q--)
    {
        int x1,y1,x2,y2;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);

        printf("%d\n",s[x2][y2]-s[x1-1][y2]-s[x2][y1-1]+s[x1-1][y1-1]);
    }
    return 0;
}


活动打卡代码 AcWing 795. 前缀和

ZJ_cao
3天前
#include <cstdio>

const int N = 1e5+10;
int n,m;
int a[N],s[N];

int main ()
{
    scanf("%d%d",&n,&m);
    for (int i = 1 ; i <= n ; i++) scanf("%d",&a[i]);
    for (int i = 1 ; i <= n ; i++) s[i]=s[i-1]+a[i];
    while(m--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        printf("%d\n",s[r]-s[l-1]);
    }
    return 0;
}


活动打卡代码 AcWing 1208. 翻硬币

ZJ_cao
3天前
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main ()
{
    int res = 0;
    string a,b;
    cin>>a>>b;

    for (int i = 0 ; i < (int)a.size() ; i++)
    {
        if (a==b) break;
        if (a[i]==b[i]) continue;
        else
        {
            if (a[i]=='o') a[i]='*';
            else a[i]='o';
            if (a[i+1]=='o') a[i+1]='*';
            else a[i+1]='o';
            res++;
        }
    }
    cout<<res<<endl;
    return 0;
}


活动打卡代码 AcWing 790. 数的三次方根

ZJ_cao
4天前
#include <cstdio>

int main ()
{
    double n;
    scanf("%lf",&n);

    double l = -10000,r = 10000;
    while(r-l>1e-7)
    {
        double mid=(l+r)/2;
        if (mid*mid*mid>=n) r = mid;
        else l = mid;
    }
    printf("%.6lf\n",l);
    return 0;
}


活动打卡代码 AcWing 789. 数的范围

ZJ_cao
4天前
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 100010;

int n, m;
int q[N];

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i ++ ) scanf("%d", &q[i]);

    for (int i = 0; i < m; i ++ )
    {
        int x;
        scanf("%d", &x);
        // 二分x的左端点
        int l = 0, r = n - 1;   // 确定区间范围
        while (l < r)
        {
            int mid = l + r >> 1;
            if (q[mid] >= x) r = mid;
            else l = mid + 1;
        }

        if (q[r] == x)
        {
            cout << r << ' ';

            // 二分x的右端点
            r = n - 1;  // 右端点一定在[左端点, n - 1] 之间
            while (l < r)
            {
                int mid = l + r + 1 >> 1;   // 因为写的是l = mid,所以需要补上1
                if (q[mid] <= x) l = mid;
                else r = mid - 1;
            }
            cout << r << endl;
        }
        else cout << "-1 -1" << endl;
    }

    return 0;
}




ZJ_cao
4天前
#include <cstdio>

int n;
int a[10];
bool st[10];

void dfs(int u)
{
    if (u==n+1)
    {
        for (int i = 1 ; i <= n ; i++)
        {
            printf("%d ",a[i]);
        }
        printf("\n");
        return;
    }

    for (int i = 1 ; i <= n ; i++)
    {
        if (!st[i])
        {
            a[u] = i;
            st[i] = true;
            dfs(u+1);
            st[i] = false;
        }
    }
}

int main ()
{
    scanf("%d",&n);
    dfs(1);
    return 0;
}



ZJ_cao
4天前
#include <cstdio>
int n;
int a[16];

void dfs(int u)
{
    if (u==n+1)
    {
        for (int i = 1 ; i <= n ; i++)
        {
            if (a[i]==1)
            printf("%d ",i);
        }
        printf("\n");
        return;
    }

    a[u]=2;
    dfs(u+1);
    a[u]=0;

    a[u]=1;
    dfs(u+1);
    a[u]=0;
}

int main ()
{
    scanf("%d",&n);

    dfs(1);
    return 0;
}