Educational Codeforces Round 89 (Rated for Div. 2) A Shovels and Swords B、Shuffle
for and Codeforces div round shuffle 89 Educational
2023-09-27 14:26:03 时间
题目链接:A、Shovels and Swords
题意:
你需要一个木棍和两个钻石可以造出来一把剑
你需要两个木棍和一个钻石可以造出来一把铁锹
你现在有a个木棍,b个钻石,问你最多可以造出来几件东西
题解:
分两种情况,第一种:
如果max(a,b)>=2*min(a,b),那么最多可以造出来min(a,b)件物品
第二种:
排除第一种情况后,假设我们最多造出来了x把铁锹,y把剑
2x+y<=a
x+2y<=b
两个式子相加得到:
3(x+y)<=a+b,即x+y<=(a+b)/3
或者你可以这样解释,我们刚开始先假设a>=b,因为最佳分配肯定是让剩余数量多的材料减去2,那么也就是a-=2,b-=1。一旦a<b,那就b-=2,a-=1。你会发现无论怎样a+b的数量都要大于3
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h> 2 #include<algorithm> 3 #include<iostream> 4 #include<string> 5 #include<queue> 6 #include<deque> 7 #include<string.h> 8 #include<map> 9 #include <iostream> 10 #include <math.h> 11 using namespace std; 12 typedef long long ll; 13 const int maxn=2e5+10; 14 int main() 15 { 16 int t; 17 scanf("%d",&t); 18 while(t--) 19 { 20 int a,b,sum=0; 21 scanf("%d%d",&a,&b); 22 if(a<b) swap(a,b); 23 if(a>=2*b) printf("%d\n",b); 24 else 25 { 26 printf("%d\n",(a+b)/3); 27 } 28 } 29 return 0; 30 }
题目链接:B、Shuffle
题意:
给你一个n个长度的数组(下标从1开始),初始这个数组每一个下标对应的值都是0,只有下标为x那个位置对应的元素值为1。然后题目中给出来m个区间,你可以在区间[l,r]中挑选出来任意两个位置l<=a<=b<=r
然后你可以让下标为a和下标为b所对应的元素值交换。问你最后有多少位置可以变成1
题解:
那下面样例做例子:
3 3 2
2 3
1 2
那么v[1]=v[2]=0,v[3]=1;
在区间[2,3]中,我们可以让v[2],v[3]交换,这样的话v[2]就有可能为1,第三个区间[1,2],因为v[2]有可能为1,那么v[1]和v[2]交换之后,那么v[1]也有可能为1
所以答案就是3
模拟题,具体实现见代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h> 2 #include<algorithm> 3 #include<iostream> 4 #include<string> 5 #include<queue> 6 #include<deque> 7 #include<string.h> 8 #include<map> 9 #include <iostream> 10 #include <math.h> 11 using namespace std; 12 typedef long long ll; 13 const int maxn=2e5+10; 14 int main() 15 { 16 int t; 17 scanf("%d",&t); 18 while(t--) 19 { 20 int n,x,m; 21 scanf("%d%d%d",&n,&x,&m); 22 int start=x,last=x; 23 while(m--) 24 { 25 int a,b; 26 scanf("%d%d",&a,&b); 27 if(a<=start && b>=last) 28 { 29 start=a; 30 last=b; 31 } 32 else if(start<=a && last>=a) 33 { 34 last=max(last,b); 35 } 36 else if(start<=b && last>=b) 37 { 38 start=min(start,a); 39 } 40 } 41 printf("%d\n",last-start+1); 42 } 43 return 0; 44 }
相关文章
- while循环优化版本-for循环
- 【论文笔记】Rethinking and Improving Relative Position Encoding for Vision Transformer
- 【论文笔记】Rich feature hierarchies for accurate oject detection and semantic segmentation
- 【计算机视觉】ViBe - a powerful technique for background detection and subtraction in video sequences
- 笔记:Six Pointers for Creating Strong Operational Business Values
- mysql 插入汉字 异常 Incorrect string value: 'xE8xA7x84xE5x88x99' for column 'name'
- Eclipse For Android 代码自动提示功能
- The operation could not be performed because OLE DB provider "SQLNCLI10" for linked server "xxx.xxx.xxx.xxx" was unable to begin a distributed transaction.
- The SQL Server Service Broker for the current database is not enabled, and as a result query notifications are not supported.
- Java EE: XML Schemas for Java EE Deployment Descriptors
- Expecting 'android:screenOrientation="unspecified"' or '"fullSensor"' for this activity so the user can use the application in any orientation and provide a great experience on Chrome OS devices
- [Medical 3D] Framework for Heterogeneous Medical Image Computing and Visualization
- ASP.NET Core – Custom Input formatters For Partial Update and Handle Under-posting
- 无论Cloud for All还是All for Cloud,Cloud才是关键!
- Using Apache Spark and MySQL for Data Analysis
- Java EE之Hibernate异常总结org.hibernate.MappingException: Repeated column in mapping for entity:
- Learning Invariant Deep Representation for NIR-VIS Face Recognition
- Holovive: A Framework For Connecting Virtual and Augmented Reality
- 【RAC】 RAC For W2K8R2 安装--grid的安装(四)
- Help for enable SSL 3.0 and disable TLS 1.0..
- JSR-330 ‘javax.inject.Inject‘ annotation found and supported for autowiring
- IBM Thread and Monitor Dump Analyzer for Java解决生产环境中的性能问题
- Unity3d windows平台基于3D WebView for Windows and macOS (Web Browser)插件打开内嵌网页支持AR/VR功能实现
- [SQL in Azure] High Availability and Disaster Recovery for SQL Server in Azure Virtual Machines
- [Windows Azure] Virtual Machine and Cloud Service Sizes for Windows Azure
- Simple:Flexible Model for MVP and MVVM(附技术分享ppt)
- [ERROR] code: 505, UNEXPECTED_FRAME - expected content header for class 60, got non content header frame instead, recoverable: false, server: true. Error: RabbitMQ Connection Closed
- eel --- A little Python library for making simple Electron-like HTML/JS GUI apps
- Vuejs(14)——在v-for中,利用index来对第一项添加class
- selenium IDE下载安装(For Chrome and firefox)