当前位置:网站首页>2022杭电多校第二场
2022杭电多校第二场
2022-07-30 07:57:00 【snuonuo】
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_data∗Q 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 ⌊365n⌋−1个。所以只需在大致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;
}
边栏推荐
猜你喜欢

hcip 第14天学习笔记
![ES报错处理-mapper [xx.xx] of different type, current_type [text], merged_type [keyword]](/img/48/064348ec4d7c2a4fa6ffe7a4778ced.png)
ES报错处理-mapper [xx.xx] of different type, current_type [text], merged_type [keyword]
![[Fun BLDC series with zero basics] Taking GD32F30x as an example, the timer related functions are explained in detail](/img/1d/700c79a766f115d5d0f3bd8263d67c.png)
[Fun BLDC series with zero basics] Taking GD32F30x as an example, the timer related functions are explained in detail

ipset restore命令维护set,但原已存在的条目未删除掉

leetcode经典问题——11.盛水最多的容器

硬件工程师

opencv可以有多有趣

HashSet and LinkedHashSet

SwiftUI SQLite 教程之 构建App本地数据库实现创建、读取、更新和删除(教程含完成项目源码)

如何组装一个注册中心
随机推荐
Field interpretation under "Surgical variables (RX SUMM-SURG OTH REG/DIS)" in SEER database
剖析SGI STL空间配置器(allocate内存分配函数)
【无标题】
Farthest Point Sampling - D-FPS vs F-FPS
剖析SGI STL空间配置器(一 、辅助接口函数)
基于SSM实现个性化健康饮食推荐系统
Hands-on teaching OneOS FOTA upgrade
瑞吉外卖项目(五) 菜品管理业务开发
One article to understand twenty kinds of switching power supply topologies
hcip实验
SQL row-column conversion
cmd命令
C语言力扣第46题之全排列。回溯法
函数(1)
一文读懂二十种开关电源拓扑结构
基于SSM开发实现校园疫情防控管理系统
tabindex attribute of input tag & tabindex attribute of a tag
英语语法-名词性从句
【WeChat Mini Program】Page Events
如何使用 Jmeter 进行抢购、秒杀等场景下,进行高并发?