cometoj(A-D+F+H)代码

A

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>


const int maxn=1e5+5;
typedef long long ll;
using namespace std;

int main()
{
    ll n;
    scanf("%lld",&n);
    ll ss=(1+n)*n/2;
     ss+=(n)*(n-1)/2;
     printf("%lld",ss);
    return 0;
}

B

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>

const int maxn=1e5+5;
typedef long long ll;
using namespace std;
int a[15];
int vis[15];
int main()
{
    int T;
    cin>>T;
    int n;
    while(T--)
    {
        scanf("%d",&n);
        for(int t=0;t<n;t++)
        {
            scanf("%d",&a[t]);
        }
        int maxx=0;
        for(int t=0;t<1<<n;t++)
        {
            memset(vis,0,sizeof(vis));
            for(int j=0;j<n;j++)
            {
             vis[n-1-j]=t>>j&1; 
            }
            int sum=0;
            for(int j=0;j<n;j++)
            {
                if(vis[j]==1)
                {
                    sum++;
                }
            }
            bool flag=false;
            for(int j=0;j<n;j++)
            {
                for(int k=j+1;k<n;k++)
                {
                    if(vis[j]==1&&vis[k]==1)
                    {
                        if(__gcd(a[j],a[k])!=1)
                        {
                            flag=true;
                        }
                    }
                }
            }
            if(flag==false)
            {
                maxx=max(maxx,sum);
            }

        }
        printf("%d
",maxx);
    }
    
    return 0;
}

C

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath>
const int maxn=1e5+5;
typedef long long ll;
using namespace std;

char str1[10*maxn],str2[10*maxn];

int main()
{
   int T;
   cin>>T;
   while(T--)
   {
       scanf("%s%s",str1,str2);
       int len1=strlen(str1);
       int len2=strlen(str2);
       if(len1==len2+2)
       {
            int cnt=0;
            for(int t=0;t<len1;t++)
            {
                if(str2[cnt]==str1[t])
                {
                    cnt++;
                }
            }
            if(cnt==len2)
            {
                printf("1
");
            }
            else
            {
                printf("0
");
            }
    }
    else
    {
        printf("0
");
    }
   }
   return 0;
}

D:


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath>
const int maxn=1e5+5;
typedef long long ll;
using namespace std;
int a[20]; int vis[25]; int main() { int x; for(int t=0;t<18;t++) { scanf("%d",&x); vis[x]++; } for(int t=1;t<14;t++) { if(vis[t]%2==0) { vis[t]=0; } else { vis[t]=1; } } int ans=0; for(int t=0;t<14;t++) { ans+=vis[t]; } cout<<ans<<endl; return 0; }

F:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath>
const int maxn=1e5+5;
typedef long long ll;
using namespace std;
int vis[1005][1005];
int dir[9][2]={{-1,0},{-1,-1},{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{-1,0}};
int n,m;
bool check(int x,int y)
{
    if(x>=1&&x<=n&&y>=1&&y<=m)
    {
        return true;
    }
    else
    {
        return false;
    }
}
int main()
{
   int q;
   cin>>n>>m>>q;
   int ans=(n-1)*(m-1);
   int x,y;
   while(q--)
   {
       scanf("%d%d",&x,&y);
       vis[x][y]=1;
       int cnt=0;
       for(int t=0;t<3;t++)
       {
           int xx=x+dir[t][0];
           int yy=y+dir[t][1];
           if(check(xx,yy)&&vis[xx][yy]==0)
           {
               cnt++;
        }
        
    }
    if(cnt==3)
    {
            
            ans--;
    }
    cnt=0;
    for(int t=2;t<5;t++)
       {
           int xx=x+dir[t][0];
           int yy=y+dir[t][1];
           if(check(xx,yy)&&vis[xx][yy]==0)
           {
               cnt++;
        }
        
    }
    if(cnt==3)
    {
            
            ans--;
    }
    cnt=0;
    for(int t=4;t<7;t++)
       {
           int xx=x+dir[t][0];
           int yy=y+dir[t][1];
           if(check(xx,yy)&&vis[xx][yy]==0)
           {
               cnt++;
        }
        
    }
    if(cnt==3)
    {
            
            ans--;
    }
    cnt=0;
    for(int t=6;t<9;t++)
       {
           int xx=x+dir[t][0];
           int yy=y+dir[t][1];
           if(check(xx,yy)&&vis[xx][yy]==0)
           {
               cnt++;
        }
        
    }
    if(cnt==3)
    {
            
            ans--;
    }
    printf("%d
",ans);
       
   }
   return 0;
}

H:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath>

const int maxn=1e5+5;
typedef long long ll;
using namespace std;
int a[2*maxn];
int main()
{
    int n;
    cin>>n;
    for(int t=0;t<n;t++)
    {
        scanf("%d",&a[t]);
    }
    bool down=true;
    int h=0x3f3f3f3f;
    int ans=0;
    for(int t=0;t<n;t++)
    {
        if(down)
        {
            if(a[t]>=h)
            {
                down=false;
                ans++;
            }        
        }
        else
        {
            if(a[t]<=h)
            {
                down=true;
            }
        
        }
        h=a[t];
    }
    cout<<ans<<endl;
    
    return 0;
}
原文地址:https://www.cnblogs.com/Staceyacm/p/10964643.html