UPC第41场,第42场部分题解

第41场

A: LR Constraints

We have N cards arranged in a row from left to right. We will write an integer between 1 and K (inclusive) on each of these cards, which are initially blank.
Given are K restrictions numbered 1 through K. Restriction i is composed of a character ci and an integer ki. If ci is L, the ki-th card from the left in the row must be the leftmost card on which we write
i. If ci is R, the ki-th card from the left in the row must be the rightmost card on which we write i.
Note that for each integer i from 1 through K, there must be at least one card on which we write i.
Find the number of ways to write integers on the cards under the K restrictions, modulo 998244353.

N个卡片,上面的数字为1~k,然后有k个限制条件,每个限制条件有1个字母(ci)和一个数字(ki),如果ci是‘L’ 表示i能够输入的最左边的位置是ki,如果ci是‘R’ 表示i能够输入的最右边的位置是ki。

Constraints
1≤N,K≤1000
ci is L or R.
1≤ki≤N
ki≠kj if i≠j.

输入

Input is given from Standard Input in the following format:
N K
c1 k1

cK kK

输出

Find the number of ways to write integers on the cards under the K restrictions in the Problem Statement, modulo 998244353.

样例输入

【样例1】
3 2
L 1
R 2
【样例2】
30 10
R 6
R 8
R 7
R 25
L 26
L 13
R 14
L 11
L 23
R 30

样例输出

【样例1】
1
【样例2】
343921442

按题目要求模拟,之后用乘法原理累计贡献即可。

code:code:code:

#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=10005,mod = 998244353;
int vis1[maxn],vis2[maxn];
ll n,k,k1;
ll s[maxn];
char ch;
int main()
{cin >> n >> k;for(int i=1;i<=k;i++){cin >> ch >> k1;vis1[k1]=1;if(ch=='L'){for(ll i=k1+1;i<=n;i++){s[i]++;}}else{for(ll i=1;i<k1;i++){s[i]++;}}}ll ans=1;for(ll i=1;i<=n;i++){if(!vis1[i]) ans=(ans*s[i])%mod;}cout << ans;return 0;
}

B: LCM of GCDs

We have a red bag, a blue bag, and N card packs. Initially, both bags are empty. Each card pack contains two cards with integers written on them. We know that the i-th card pack contains a card with ai and another with bi.
For each card pack, we will put one of its cards in the red bag, and the other in the blue bag.
After we put all cards in the bags, let X be the greatest common divisor of all integers written on cards in the red bag. Similarly, let Y be the greatest common divisor of all integers written on cards in the blue bag. Our score will be the least common multiple of X and Y.

Find the maximum possible score.

我们有一个红色的包,一个蓝色的包和N个卡片包。最初,两个袋子都是空的。每个卡片包包含两张写有整数的卡片。我们知道,第i个卡包包含一张ai卡和另一张bi卡。

对于每个卡片包,我们将把它的一张卡片放在红色的袋子里,另一张放在蓝色的袋子里。

当我们把所有的卡片放在袋子里之后,让X成为红色袋子里卡片上所有整数的最大公约数。类似地,让Y是写在蓝包卡片上的所有整数的最大公约数。我们的分数将是X和Y的最小公倍数。

找出可能的最大分数。

Constraints
All values in input are integers.
1≤N≤50
1≤ai,bi≤109

输入

Input is given from Standard Input in the following format:
N
a1 b1

aN bN

输出

Print the maximum possible score.

样例输入

【样例1】
2
2 15
10 6
【样例2】
5
148834018 644854700
947642099 255192490
35137537 134714230
944287156 528403260
68656286 200621680
【样例3】
20
557057460 31783488
843507940 794587200
640711140 620259584
1901220 499867584
190122000 41414848
349507610 620259584
890404700 609665088
392918800 211889920
507308870 722352000
156850650 498904448
806117280 862969856
193607570 992030080
660673950 422816704
622015810 563434560
207866720 316871744
63057130 117502592
482593010 366954816
605221700 705015552
702500790 900532160
171743540 353470912

样例输出

【样例1】
10
【样例2】
238630
【样例3】
152594452160

注意到N<=50,每次的选择只有两种情况,a[i],b[i]a[i],b[i]a[i],b[i],or b[i],a[i]b[i],a[i]b[i],a[i],不妨直接暴力dfs,这里为了阻止搜索过程中的无效回溯,使用集合标记我们做过的过程,可以大大减少时间。

codecodecode:

#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include <vector>
#include <set>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=105,mod = 998244353;
int a[maxn], b[maxn];
int n;
ll ans = 1;
set<pair<pair<int,int>,int>>st;
void dfs(ll d1,ll d2,int c)
{if(st.count({{d1, d2}, c})){return ;}if(c==n+1){ans=max(ans,d1/__gcd(d1,d2)*d2);return;}st.insert({{d1,d2},c});dfs(__gcd(d1,(ll)a[c]), __gcd(d2,(ll)b[c]), c+1);dfs(__gcd(d1,(ll)b[c]), __gcd(d2,(ll)a[c]), c+1);
}
int main()
{cin >> n;for(int i=1;i<=n;i++){scanf("%d%d", &a[i], &b[i]);}dfs(a[1],b[1],2);cout << ans ;
}

D.Garbage Classification

On the CVBB planet, garbage classification has been gradually executed to help save resources and protect the environment. Nowadays people have to be equipped with knowledge of distinguishing different types of garbage. Now, given the waste compositions of a discarded product, you are asked to determine which category it belongs to.

The waste compositions are represented as a string s consisting of only lowercase letters, where each letter represents a waste composition and has an equal proportion. Each waste composition in that product is in one of the three situations, dry, wet or harmful.

The product can be classified by the following rules:

In case that at least 25% of its compositions is harmful, it is harmful garbage.
In case that at most 10% of its compositions is harmful, it is recyclable garbage.
In other cases, if the proportion of dry compositions in it is at least twice that of wet compositions, it is dry garbage, or otherwise, it is wet garbage.

输入

There are multiple test cases. The first line contains an integer T (1≤T≤50), indicating the number of test cases. Test cases are given in the following.

For each test case, the first line contains a non-empty string s (1≤∣s∣≤2000) consisting of only lowercase letters.

The second line contains a string t of length 26, consisting of only characters in {d,w,h}. The i-th character of t represents the situation of the waste composition denoted by the i-th lowercase letter, where ‘d’, ‘w’ and ‘h’ mean dry, wet or harmful respectively.

输出

For each test case, output “Case #x: y” in one line (without quotes), where x indicates the case number starting from 1, and y (y∈{Harmful,Recyclable,Dry,Wet}) denotes the garbage type of the product in this test case.

样例输入

4
dqxxjefgctjgdbqxphff
hddhddhhhdhdhwwddhhdwwdhhw
iqdvfzzdqsbdevzebego
wdhddwwhwhdhhhwwdwdhwdwhhd
erkjqzsmchcmbqeasadf
dwddddwdwdwhdwhhdhhwwhhwdh
mcxkwmxxlhbrymwawhio
ddhwhddhwwwdddwdwhwwwhdwdw

样例输出

Case #1: Harmful
Case #2: Recyclable
Case #3: Dry
Case #4: Wet

还是模拟题。。。

code:code:code:

#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=100005;
int n,cnt=0;
int m;
int main()
{string s,s1;cin >> m;while(m--){cin >> s1;cin >> s;double sum1=0,sum2=0,sum3=0;int n=s1.length();for(int i=0;i<n;i++){int k=s1[i]-'a';if(s[k]=='d'){sum1++;}else if(s[k]=='w'){sum2++;}else if(s[k]=='h'){sum3++;}}printf("Case #%d: ",++cnt);//cout << sum1 << " " << sum2 << " " << sum3 << endl;if(sum3/n>=0.25){printf("Harmful\n");}else if(sum3/n<=0.1){printf("Recyclable\n");}else{if(sum1>=sum2*2){printf("Dry\n");}else{printf("Wet\n");}}}return 0;
}

L.铺设道路

春春是一名道路工程师,负责铺设一条长度为n的道路。
铺设道路的主要工作是填平下陷的地表。整段道路可以看作是n块首尾相连的区域,一开始,第i块区域下陷的深度为di。
春春每天可以选择一段连续区间[L,R],填充这段区间中的每块区域,让其下陷深度减少1。在选择区间时,需要保证,区间内的每块区域在填充前下陷深度均不为0。
春春希望你能帮他设计一种方案,可以在最短的时间内将整段道路的下陷深度都变为0。

输入

输入包含两行,第一行包含一个整数n,表示道路的长度。
第二行包含n个整数,相邻两数间用一个空格隔开,第i个整数为di。

输出

输出仅包含一个整数,即最少需要多少天才能完成任务。

样例输入

6
4 3 2 5 3 5

样例输出

9

贪心,如果相邻后者小于前者,前者的填充一定会覆盖后者;反之,后者就需要再进行铺设,铺设的量为a[i]-a[i-1]。

code:code:code:

#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=100005;
int n,tot=0;
ll a[maxn];
int main()
{int n;ll ans=0;cin >> n;for(int i=1;i<=n;i++){cin >> a[i];}for(int i=1;i<=n+1;i++){if(i!=1){if(a[i]<a[i-1]){ans+=abs(a[i]-a[i-1]);}}}cout << ans << endl;return 0;
}

F: Is Today Friday?

No, it’s not Friday

UPC第41场,第42场部分题解相关推荐

  1. 这是我面试 42 场拿下字节、微软 offer 的方法论!

    点击上方关注 前端技术江湖,一起学习,天天进步 我在 7 周内一共面试了 42 场,最终拿了微软.蚂蚁.B站.字节.Conviva 的 5 个 Offer.上图是我的面试时间表我有些东西希望能够分享给 ...

  2. 这是我面试42场拿下微软、蚂蚁、头条offer的方法论

    我在 7 周内一共面试了 42 场,最终拿了微软.蚂蚁.B 站.字节.Conviva 的 5 个 Offer.上图是我的面试时间表我有些东西希望能够分享给大家,不仅仅是简单的面经,包括: 锁定目标 关 ...

  3. 面试42场拿下微软、蚂蚁、头条offer的方法论(干货)

    点击上方"蓝色字体",选择"设为星标" 做积极向上的前端人! 我在 7 周内一共面试了 42 场,最终拿了微软.蚂蚁.B站.字节.Conviva 的 5 个 O ...

  4. 华彩谢幕:一场游戏一场梦 | 一点财经

    2018年初,很多人认为,瑞典管理学大师斯文·艾里克·肖斯特兰在<管理的两面性>阐述的观点正在腾讯这头大象身上失效. 肖斯特兰认为,成功的领导艺术,能够在理性与非理性元素的交错中找到平衡点 ...

  5. 深圳赏给我的耳光:说到底,生活就是一场接着一场的较量

    本文转载自公众号 | 马桶好读 作者 | 花名九爷 15年前的夏至,涛子从陕西老家来到深圳,钻过桥洞,睡过洪湖公园. 现在涛子是一家服装公司老板,身家大几千万.他说自己刚来深圳的时候很苦.很窘迫,活得 ...

  6. C/C++描述 第十一届蓝桥杯省赛 C/C++ 大学C组 第一场(2020.7.5) 题目+题解

    C/C++描述 第十一届蓝桥杯省赛 第一场(2020.7.5) 题目+题解   大家好,我叫亓官劼(qí guān jié ),在CSDN中记录学习的点滴历程,时光荏苒,未来可期,加油~博客地址为:亓 ...

  7. 2225. 找出输掉零场或一场比赛的玩家

    2225. 找出输掉零场或一场比赛的玩家 给你一个整数数组 matches 其中 matches[i] = [winneri, loseri] 表示在一场比赛中 winneri 击败了 loseri ...

  8. 博客大赛,我的一场生意一场梦

    博客大赛,我的一场生意一场梦 2010年最后一天结束了,在这一天中自己经历了几件也许会让自己一辈子都记得的事情.这几件事情,有高兴的也有不痛快的,也许是自己老了有些事情淡定了,也许是情绪发生了化学反应 ...

  9. iOS解决控制器转场和返场界面卡顿的一种方法

    本博介绍了在控制器转场和返场时界面发生卡顿的一种解决方法,主要思想是使用视图快照功能来提供一个静态的伪视图以提高性能. 转场和返场 转场是指从控制器A切换到控制器B中,这意味着控制器A被隐藏: 控制器 ...

最新文章

  1. 游标对于分页存储过程
  2. TCP/IP详解--第七章
  3. TCP/IP协议的一个具体实现Socket
  4. python 日志不会按照日期分割_python日志切割保留一个月
  5. 重温2 在Activity中使用Menu
  6. tomcat启动报错APR问题
  7. 面向Linux的10款最佳剪贴板管理器
  8. 极限 lim(x^x-(sinx)^x)/(x²arctanx)
  9. linux 路由跟踪命令_云计算网络知识学习-linux网络基础
  10. dvbbs 7.1版块图标感应渐变效果 From www.jfeng.cn
  11. OpenGL编程指南(第七版)
  12. 计算机知识脑筋急转弯,10道智力题图片及答案大全|2018年朋友圈最烧脑的10道智力题 附答案_最火软件站...
  13. 使用weblogic部署若依项目(图文教程)
  14. ZigBee空气质量监测系统设计
  15. ai怎么调界面大小_ai软件界面字体特别小 ai菜单栏字体大小怎么改
  16. LVDS信号与TTL信号
  17. c# Environment.GetCommandLineArgs
  18. ROS2极简总结-新增概念
  19. 国产数据库mysql_国产的数据库都有哪些?
  20. 华工计算机网络辅修,【JZT干货】双手献上华工辅修攻略

热门文章

  1. linux挂载img镜像文件,如何挂载.img格式的镜像
  2. Error:Cannot build artifact because it is included into a circuladependency
  3. 详解css设置默认字体
  4. sap服务器迁移性能问题,专家详解SAP数据迁移的六个方法
  5. 简单网页制作的一些基础格式
  6. python爬取pubmed的文献_爬虫获取pubmed中文献的标题和摘要
  7. 在Winform中上传文件的工具类-ResourceMgr
  8. 沉浸式过山车 梦幻新体验
  9. 期中计算机网络答案,计算机网络基础自考试题「附答案」
  10. python中如何判断一个字符串是否可以转换为数字