• 2022杭电多校第二场


    1001

    1002 C++ to Python

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

    • 思路

    • 代码

    #include
    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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    1003

    1004

    1005

    1006

    1007 Snatch Groceries

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

    • 思路

    • 代码

    #include
    #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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47

    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
    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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    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
    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<
    				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<
    					break;
    				}
    			}
    		}
    		cout<<ans<<endl;
    	}
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
  • 相关阅读:
    【最长上升子序列】【博弈论】Game on Permutation—CF1860C
    浅谈研发与制造运营双端之间的数字化探索
    PHP表单处理的案例分析
    【机器学习】数据格式csv/txt/pkl
    14. UART串口通信
    信奥中的数学:集合与子集
    leetcode70爬楼梯
    mac系统废纸篓可以恢复么,mac不小心清空了废纸篓怎么找回
    芯科蓝牙BG27开发笔记2-调试第一个程序
    本周SQL优化实战分享
  • 原文地址:https://blog.csdn.net/weixin_45270761/article/details/125929826