2022杭电多校第二场

1001

1002 C++ to Python

  • 题意
    给定一个python里合法的字符串,将其转化为C++合法的字符串。

  • 思路

  • 代码

#include<bits/stdc++.h>
using namespace std;
int n,t;
char s[1010];
vector<char> v;

int main()
{
	cin>>t;
	while(t--)
	{
		cin>>s;
		n=strlen(s);
		v.clear();
		for(int i=0;i<n;i++)
		{
			while(s[i]!=',' && s[i]!='(' && s[i]!=')' && !(s[i]>='0'&&s[i]<='9') && s[i]!='-') i++;
			v.push_back(s[i]);
		}
		for(auto i:v) printf("%c",i);
		puts("");
	}
	return 0;
}

1003

1004

1005

1006

1007 Snatch Groceries

  • 题意
    超长的阅读理解题:大意是给定一些区间,判断这些区间会不会重叠。

  • 思路

  • 代码

#include<bits/stdc++.h>
#define N 100010
#define ll long long
using namespace std;

ll t,n;

struct node
{
    int a,b;
}p[N];

bool cmp1(struct node x, struct node y)
{
    if(x.a==y.a) return x.b<y.b;
    else return x.a<y.a;
}
int main()
{
    cin>>t;
    while(t--)
    {
        scanf("%lld",&n);
        //p[0].a=0,p[0].b=0,p[0].c=0;
        ll ans=0;
        for(int i=1; i<=n; i++)
        {
            scanf("%d%d",&p[i].a,&p[i].b);
        }
        sort(p+1,p+1+n,cmp1);
        if(n==1)printf("1\n");
        else
        {
            for(int i=2; i<=n; i++)
            {
                if(p[i].a>p[i-1].b)
                {
                    ans++;
                    if(i==n)ans++;
                }
                else break;
            }
            printf("%lld\n",ans);
        }
    }
    return 0;
}

1008

1009 ShuanQ

  • 题意
    在这里插入图片描述

  • 思路
    在这里插入图片描述
    找到合法的M,然后输出 e n c r y p t e d _ d a t a ∗ Q   m o d   M encrypted\_data*Q\ mod\ M encrypted_dataQ mod M即可。

  • 代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int t;
ll p,q,s,m;
ll divide(ll x)
{
    for (ll i = 2; i <= x / i; i ++ )
        if (x % i == 0)
        {
            while (x % i == 0) x /= i;
            if(i>p && i>q && i>s) return i;
        }
    if (x>p && x>q && x>s) return x;
    else return -1;
}

int main()
{
	cin>>t;
	while(t--)
	{
		scanf("%lld%lld%lld",&p,&q,&s);
		m=divide(p*q-1);
		if(m==-1) printf("shuanQ\n");
		else                          
		{
			printf("%lld\n",s*q%m);
		}
	}
	return 0;
}

1010

1011

1012 Luxury cruise ship

  • 题意
    有无数个面值为7、31、365的硬币,问能不能组成n,能组成的话最少需要多少枚硬币。
  • 思路
    由于 l c m ( 7 , 31 ) < 365 lcm(7,31)< 365 lcm(7,31)<365,因此365只会取 ⌊ n 365 ⌋ \lfloor {\frac{n}{365}}\rfloor 365n个或者 ⌊ n 365 ⌋ − 1 \lfloor {\frac{n}{365}}\rfloor-1 365n1个。所以只需在大致0-365范围内或者0-2*365范围内判断31的取法是否合法(余数能不能被7整除)即可。
  • 代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int t;
ll n;
int main()
{
	cin>>t;
	ll a=7,b=31,c=365;
	while(t--)
	{
		scanf("%lld",&n);
		ll ans=-1;
		ll num_c=n/c;
		bool fl=false;
		for(int num_b=(n-num_c*c)/b;num_b>=0;num_b--)
		{
			if((n-num_c*c-num_b*b)%a==0) 
			{
				ll num_a=(n-num_c*c-num_b*b)/a;
				ans=num_c+num_b+num_a;
				fl=true;
//				cout<<num_a<<" "<<num_b<<" "<<num_c<<endl;
				break;
			}
		}
		if(fl==false)
		{
			ll num_c=n/c-1;
			if(num_c<0) fl=true;
			for(int num_b=(n-num_c*c)/b;num_b>=0&&!fl;num_b--)
			{
				if((n-num_c*c-num_b*b)%a==0) 
				{
					ll num_a=(n-num_c*c-num_b*b)/a;
					ans=num_c+num_b+num_a;
//					cout<<num_a<<" "<<num_b<<" "<<num_c<<endl;
					break;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值