05.24 ICPC 2019-2020 North-Western Russia Regional Contest复现赛+Codeforces Round #645 (Div. 2)
A.Accurate Movement(复现赛)
题意:两个木块最左边都在0的位置,最右边分别为a,b(b>a),并且短的木条只能在长木条内移动,问两个木条需要移动多少次才能使两个木条的右端都在n
思路:短木条最少移动(n-a)/(b-a),如果(n-a)%(b-a)不为0,那么还需要再多移动一次,才能到达最右边,长木条以此类推
代码:
1 #include<iostream>
2 #include<algorithm>
3 #include<cmath>
4 #include<cstdio>
5 using namespace std;
6 int main(){
7 int a,b,n;
8 scanf("%d %d %d",&a,&b,&n);
9 int sum=0;
10 if((n-a)%(b-a)==0){
11 sum+=(n-a)/(b-a);
12 }else{
13 sum+=(n-a)/(b-a)+1;
14 }
15 if((n-b)%(b-a)==0){
16 sum+=(n-b)/(b-a);
17 }else{
18 sum+=(n-b)/(b-a)+1;
19 }
20 printf("%d\n",sum);
21 }
A. Park Lighting(#645)
题意:安放路灯在棱上,可以点亮以这条楞为公共线的正方形小块上,问需要多少个灯才能点亮整个大矩形,输入为大矩形的场合宽
思路:直接判断矩形个数是不是偶数,如果是,那么就可以用(长×宽)/2,如果不是,就是需要额外的一个点亮剩下的一个
代码:
1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cmath>
5 using namespace std;
6 int main(){
7 int t;
8 scanf("%d",&t);
9 while(t--){
10 int a,b;
11 scanf("%d %d",&a,&b);
12 if((a*b)%2==1){
13 printf("%d\n",a*b/2+1);
14 }else{
15 printf("%d\n",a*b/2);
16 }
17 }
18 }
B. Maria Breaks the Self-isolation
题意:起初院子中一个老奶奶,然后它可以喊任意个其他的老奶奶,但是这些老奶奶出现的要求是,当她出现时必须看到除她以外的a[i]个人,判断院子中最多可以喊多少个老奶奶
思路:采用优先队列,从需要看见人数最多的老奶奶开始,如果这个数小于1加上院子中可进去的人数(先假设同时间去),那么就说明可以同时来,如果大于,也就是说即使同一时间进去也不能满足最后一个老奶奶,然后出栈(为了变化top)
wa掉的/注意的:1.需要从最大到最小遍历,因为这样能知道确切的这个人是不是进的去进不去,这样一来需要思考的变化因素就很少,不用天南海北的进行纠结到底怎么选;2.其实这种做法有种第一次打电话就给所有的人打电话,从最后向前遍历,找到是不是真的可以满足,每个人都开心的进院子;3.一定出栈进行变换top;4.我不知道我为什么用sort就超时了,用优先队列就不超时
代码:
1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cmath>
5 #include<queue>
6 using namespace std;
7 int main(){
8 int t;
9 scanf("%d",&t);
10 while(t--){
11 int r,n;
12 scanf("%d",&n);
13 priority_queue<int> a;
14 for(int i=0;i<n;i++){
15 scanf("%d",&r);
16 a.push(r);
17 }
18 int s=0,m=n;
19
20 for(int i=0;i<n;i++){
21 if(a.top()<1+m){
22 s++;
23 }else{
24 m--;
25 }
26 a.pop();
27 }
28 printf("%d\n",s+1);
29 }
30 }
我实在是太菜了,导致我最近做的题不是很多,但是时间话得特别长,还是应该偶尔看看算法书,只靠思维题是不行了,而且有的思维题读题真的好麻烦,最近专业课落得好多,绝望!!!
05.24 ICPC 2019-2020 North-Western Russia Regional Contest复现赛+Codeforces Round #645 (Div. 2)的更多相关文章
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)
Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...
- 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest
2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest A - Arranging Wine 题目描述:有\(R\)个红箱和\(W\)个白箱,将这 ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)
A - Forgetting Things 题意:给 \(a,b\) 两个数字的开头数字(1~9),求使得等式 \(a=b-1\) 成立的一组 \(a,b\) ,无解输出-1. 题解:很显然只有 \( ...
- ICPC 2019-2020 North-Western Russia Regional Contest
目录 Contest Info Solutions Problem A. Accurate Movement Problem B. Bad Treap Problem E. Equidistant P ...
- ICPC Central Russia Regional Contest (CRRC 19)题解
题目连接:https://codeforces.com/gym/102780 寒假第二次训练赛,(某菜依旧是4个小时后咕咕咕),战况还行,个人表现极差(高级演员) A:Green tea 暴力枚举即可 ...
- Codeforces Round #268 (Div. 1) A. 24 Game 构造
A. 24 Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/468/problem/A D ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) D. Power Products 数学 暴力
D. Power Products You are given n positive integers a1,-,an, and an integer k≥2. Count the number of ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) C. p-binary 水题
C. p-binary Vasya will fancy any number as long as it is an integer power of two. Petya, on the othe ...
- Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4) 题解
Happy Birthday, Polycarp! Make Them Odd As Simple as One and Two Let's Play the Words? Two Fairs Bea ...
随机推荐
- 第一个win32程序
vs2017下自动创建的窗口程序 // win_test.cpp : 定义应用程序的入口点. // #include "framework.h" #include "wi ...
- SqlServer视图的创建与使用
SqlServer系列之视图的创建与使用: 什么是视图? 视图的概述 在数据查询中,可以看到数据表设计过程中,考虑到数据的冗余度低.数据一致性等问题,通常对数据表的设计要满足范式的要求,因此也会造成一 ...
- 如何开发一个APP——转自知乎
作者:简单点链接:https://www.zhihu.com/question/22999185/answer/155469014来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...
- 消息中间件-ActiveMQ支持的消息协议
package com.study.mq.a1_example.helloworld.queue; import org.apache.activemq.ActiveMQConnectionFacto ...
- 「Spring Boot 2.4 新特性」一键构建Docker镜像
背景 在我们开发过程中为了支持 Docker 容器化,一般使用 Maven 编译打包然后生成镜像,能够大大提供上线效率,同时能够快速动态扩容,快速回滚,着实很方便.docker-maven-plugi ...
- 算法、数据结构、与设计模式等在游戏开发中的运用 (一):单例设计(Singleton Design)
算法.数据结构.与设计模式等在游戏开发中的运用 (一):单例设计(Singleton Design) 作者: Compasslg 李涵威 1. 什么是单例设计(Singleton Design) 在学 ...
- N 皇后-力扣解题
n 皇后问题 研究的是如何将 n 个皇后放置在 n*n 的棋盘上,并且使皇后彼此之间不能相互攻击. 给你一个整数 n ,返回所有不同的 n 皇后问题 的解决方案. 每一种解法包含一个不同的 n 皇后问 ...
- 1057 Stack
Stack is one of the most fundamental data structures, which is based on the principle of Last In Fir ...
- odoo字段属性列举
罗列一些Odoo中的字段属性,基本包含大部分的属性. 常用字段属性 平平无奇常用字段属性 string:字段的标题,在UI视图标签中使用.它是可选项,如未设置,会通过首字母大写及将空格替换成为下划线来 ...
- 【网络协议】OSI七层模型 和TCP/IP五层模型
OSI(Open System Interconnection)七层模型 TCP/IP 五层模型