2018多校1补题

第一道当时没做出来,后来看题解补了

n=x+y+z,x|n,y|n,z|n  -->  n/x,n/y,n/z都是整数,令其为abc  -->1/a+1/b+1/c=1,abc为整数

解这个方程发现abc只有2,4,4和3,3,3和2,3,6这三个值,由于2,3,6情况里面有6,满足这个的肯定满足3,3,3,而且肯定值小于3,3,3所以舍弃

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--)
    {
        long long n;
        cin>>n;
        if(n%3==0)cout<<n*n*n/27<<endl;
        else if(n%4==0)cout<<n*n*n/32<<endl;
        else cout<<-1<<endl;
    }
}


第二道还是没有做出来,后来补的

首先看只有一组的情况,使用一个栈可以得到这一组里面有多少括号配对,一旦栈顶是 ( 的时候 ) 入栈则得到一个配对。由于这个栈只可能长成)))))((((((((这种样子,所以不用确实的开一个栈,只用拿变量记录就行。处理完一组以后会得到配对数和一个))))((((这样的栈,记录这里的左右括号的数量留到后面用

然后是多组的情况,题解上面给了个xjb贪心的思路:)比(多的肯定排在)比(少的组后面,对于都是)比(少的组,)越少排的越前,)比(多的组,(越少排的越后

 

#include <bits/stdc++.h>

using namespace std;
const int maxn=100000;
bool cmp(const pair<int,int>&a,const pair<int,int>&b)
{
    if(a.first >= a.second && b.first < b.second)
			return false;
		if(a.first < a.second && b.first >= b.second)
			return true;
		if(a.first >= a.second && b.first >= b.second)
			return a.second > b.second;
		return a.first < b.first;
}
int main()
{
    int t;
    scanf("%d",&t);
    //cin>>t;
    while(t--)
    {
        int n;
        scanf("%d",&n);
        //cin>>n;
        int su=0;
        pair<int,int>arr[maxn];
        char buff[maxn];
        for(int i=0;i<n;i++)
        {
            scanf("%s",buff);
            int pos=0,l=0,r=0;
            for(int j=0;j<strlen(buff);j++)//l:(  r:)
            {
                if(l>0)
                {
                    if(buff[j]=='(')l++;
                    else {l--;su++;}
                }
                else
                {
                    if(buff[j]=='(')l++;
                    else r++;
                }
            }
            arr[i].first=r;
            arr[i].second=l;

        }
        sort(arr,arr+n,cmp);
        int now=0;
        for(int i=0;i<n;i++)
        {
            //cout<<"**"<<arr[i].first<<" "<<arr[i].second<<endl;

            if(now>=arr[i].first)
                {su+=arr[i].first;now-=arr[i].first;now+=arr[i].second;}
            else

                {su+=now;now=arr[i].second;}



        }
        printf("%d\n",2*su);
          }
}

第三道做出来了,不过想多了,只用拿x排个序就行了,我把xy都排了

 

#include <bits/stdc++.h>

using namespace std;

struct st
{
    int x,y,num;
};
bool cmp(const st&a,const st&b)
{
    if(a.y==b.y)return a.y<b.y;
    return a.x<b.x;
}
int main()
{
    int t;
    cin>>t;
    while(t--)

    {
        int n;
        cin>>n;
        vector<st>vec;
        vec.reserve(3*n);
        st cur;
        int num=1;
        for(int i=0;i<3*n;i++)
        {
            cin>>cur.x>>cur.y;
            cur.num=num;
            num++;
            vec.push_back(cur);

        }
        sort(vec.begin(),vec.end(),cmp);
        for(int i=0;i<3*n;i+=3)
        {
            cout<<vec[i].num<<" "<<vec[i+1].num<<" "<<vec[i+2].num<<endl;
        }
    }
    return 0;
}

 

第四道没做出来,看了题解做的

首先是对于给的区间,如果一个区间被另外一个包含,那么这个肯定是没用的可以丢掉,然后是对于两个区间有重合的情况,可以看出,前面一个保持连续,由于前一个不重合的部分不会被后一个考虑,后一个对不重合的部分重新开始就行,相当于是后面一个把重合部分砍掉成新的区间。把区间排个序从左到右处理即可。

拿一个优先队列q保存可以放到序列里面的元素。初始化为1-n,每次的处理就是取一个区间,把前一个区间的释放掉,然后处理后面的内容。

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
int a[1000005],_;
struct node
{
    int l,r;
};
bool cmp(const node&a,const node&n1)
{
    return a.l<n1.l||(a.l==n1.l&&a.r>n1.r);
}
node vec[1000005];
int ans[1000005];
int main()
{
 //   freopen("in.txt","r",stdin);
  //  freopen("out1.txt","w",stdout);

    for (scanf("%d",&_);_;_--)
    {
        int n,m;
        scanf("%d%d",&n,&m);

        rep(i,0,m)
        {
            scanf("%d%d",&vec[i].l,&vec[i].r);
        }
        sort(vec,vec+m,cmp);
        //memset(ans,0,sizeof(ans));
        priority_queue<int,vector<int>,greater<int> >q;
        rep(i,1,n+1){q.push(i);ans[i]=1;}
        rep(i,vec[0].l,vec[0].r+1){ans[i]=q.top();q.pop();}
        int las=0;
        rep(i,1,m)
        {
            if(vec[i].r<vec[las].r)continue;
            for(int j=vec[las].l;j<=min(vec[i].l-1,vec[las].r);j++)
            {
                q.push(ans[j]);
              //  cout<<"**"<<ans[j]<<endl;
            }
            if(vec[i].l<=vec[las].r)rep(j,vec[las].r+1,vec[i].r+1){ans[j]=q.top();q.pop();}
            else rep(j,vec[i].l,vec[i].r+1){ans[j]=q.top();q.pop();}
            las=i;
        }
       // rep(i,1,n+1)cout<<ans[i]<<" ";cout<<endl;
        rep(i,1,n)printf("%d ",ans[i]);printf("%d\n",ans[n]);
    }
  //  fclose(stdin);
  //  fclose(stdout);
}

 

第十一道做出来了,一个模拟

#include <bits/stdc++.h>

using namespace std;

int main()
{
  /*  float c;
    cin>>c;
    cout<<c-(int)c;*/

    int t;
    scanf("%d",&t);
    while(t--)
    {
        int h,m,iao,c;

        char mark,pan;

        scanf("%d %d%*4c%c%d%c",&h,&m,&mark,&c,&pan);
        if(pan=='.')
        scanf("%d",&iao);
        else iao=0;
        iao*=6;
        h-=8;
        if(mark=='+')
        {
            h+=(int)c;
            m+=iao;
        }


        else
        {
            h-=(int)c;
           // if(iao!=0)h--;
            m-=iao;
        }
        if(m<0){m+=60;h--;}
        if(m>=60){m-=60;h++;}
        if(h<0)h+=24;
        if(h>23)h-=24;
        printf("%02d:%02d\n",h,m);
      /*  cout<<h<<":";
        if(m<10)cout<<0;
        cout<<m<<endl;*/
        //cout<<h<<" "<<m<<" "<<c<<endl;
    }
    return 0;

}

然后看题解的时候看到了一个方便的头

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值