Codeforces 1256A 1257A
题目链接:https://codeforces.com/problemset/problem/1256/A
1 second
256 megabytes
standard input
standard output
You have aa coins of value nn and bb coins of value 11. You always pay in exact change, so you want to know if there exist such xx and yy that if you take xx (0≤x≤a0≤x≤a) coins of value nn and yy (0≤y≤b0≤y≤b) coins of value 11, then the total value of taken coins will be SS.
You have to answer qq independent test cases.
The first line of the input contains one integer qq (1≤q≤1041≤q≤104) — the number of test cases. Then qq test cases follow.
The only line of the test case contains four integers aa, bb, nn and SS (1≤a,b,n,S≤1091≤a,b,n,S≤109) — the number of coins of value nn, the number of coins of value 11, the value nn and the required total value.
For the ii-th test case print the answer on it — YES (without quotes) if there exist such xx and yy that if you take xx coins of value nn and yy coins of value 11, then the total value of taken coins will be SS, and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
4
1 2 3 4
1 2 3 6
5 2 6 27
3 3 5 18
YES
NO
NO
YES
思路:输入a,b,n,s,每个代表的意思为:a个含有价值n的硬币、b个含有价值1的硬币、价值为n的硬币、由这些硬币组成的目标数。先判断b个为1的硬币是否能直接达到s,能的话则直接输出,不能的话则进行下一步。
先判断价值为n的硬币最多能取多少个,即s对n取整,再将s减去s/n,再判断剩下的能不能由b个价值为1的硬币组成,能的话则满足,不能的话则不满足。
AC代码
#include<iostream>
#include<cmath>
using namespace std; int main()
{
int q;
cin >> q;
while(q--)
{
int a = ,b = ,sum = ,n = ,s = ,temp = ,min1 = ;
cin >> a >> b >> n >> s;
if(b >= s)
{
cout << "YES" << endl;
continue;
}
temp = s / n;
min1 = min(a,temp);
sum = s - min1 * n;
if(b >= sum)
{
cout << "YES" << endl;
continue;
}
else
{
cout << "NO" << endl;
continue;
}
}
return ;
}
题目链接:https://codeforces.com/contest/1257/problem/A
1 second
256 megabytes
standard input
standard output
You are the gym teacher in the school.
There are nn students in the row. And there are two rivalling students among them. The first one is in position aa, the second in position bb. Positions are numbered from 11 to nn from left to right.
Since they are rivals, you want to maximize the distance between them. If students are in positions pp and ss respectively, then distance between them is |p−s||p−s|.
You can do the following operation at most xx times: choose two adjacent (neighbouring) students and swap them.
Calculate the maximum distance between two rivalling students after at most xx swaps.
The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.
The only line of each test case contains four integers nn, xx, aa and bb (2≤n≤1002≤n≤100, 0≤x≤1000≤x≤100, 1≤a,b≤n1≤a,b≤n, a≠ba≠b) — the number of students in the row, the number of swaps which you can do, and positions of first and second rivaling students respectively.
For each test case print one integer — the maximum distance between two rivaling students which you can obtain.
3
5 1 3 2
100 33 100 1
6 0 2 3
2
99
1
In the first test case you can swap students in positions 33 and 44. And then the distance between the rivals is equal to |4−2|=2|4−2|=2.
In the second test case you don't have to swap students.
In the third test case you can't swap students.
思路:情况1:两个人的距离加上可移动的次数都小于等于最远距离的话,直接输出。
情况2:两个人的距离加上可移动距离大于最远距离,则说明可移动次数x足够用了。再来判断,要使两个人达到最远距离,与最远距离还差多少,如果可移动次数x大于差值,则两人的距离可达最大,否则两个人的最远距离为原先的距离加上可移动距离x,即为答案
AC代码
#include<iostream>
#include<cmath>
using namespace std; int main()
{
int t;
cin >> t;
while(t--)
{
int juli,n,x,a,b;
cin >> n >> x >> a >> b;
juli = abs(a - b);
if(juli + x <= n - )//移动后的距离 小于等于 最远距离
{
cout << x + juli << endl;//直接输出
continue;
}
if(n - juli <= x)//n-juli为 离最远距离差多少
{
cout << n - << endl;
continue;
}
else
{
cout << juli + x << endl;
continue;
}
}
return ;
}
//100 25 70 10
Codeforces 1256A 1257A的更多相关文章
- java处理中国气象数据,提取汇总陕西地区24小时各观测点的数据(csv格式)
1.先贴一下气象数据的csv源格式,由于数据内容较多,就放一部分(china_sites_20150102.csv) date,hour,type,1001A,1002A,1003A,1004A,10 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- HTTP中的301、302、303、307、308
结论 3XX开头的HTTP状态码都表示重定向的响应. 301.308是永久重定向:302.303.307是临时重定向. 301.302是http 1.0的内容,303.307.308是http1.1的 ...
- 如何通过纯javascript实现表单提交
通常,如果是POST方法,一般使用vuejs+axios,或使用Jquery实现表单提交.有些地方,我想使用纯JS实现,比方简单的登陆跳转.话不多说,看原代码, laravel中的HTML部分,如果不 ...
- QML::Rectangle组件
QML的Rectangle组件,描绘一个矩形,一个可视化的对象. 外加设置属性来达到我们想要的效果.常用的有矩形的颜色,边框颜色,圆角等设置. Rectangle{ x:10//这里的坐标是相对于它的 ...
- SpringBoot+Thyemelaf开发环境正常,打包jar发到服务器就报错Template might not exist or might not be accessible
这里说一下Thyemelaf的巨坑 写了一个SpringBoot+Thyemelaf的项目,并不是前后端分离.今天想放到linux服务器上玩玩,打成jar包,然后一运行他妈居然报错了,报了一个Temp ...
- bayaim_mysql_忘记密码 [仅限 5.6以下]
bayaim_mysql_忘记密码 [仅限 5.6以下] 原创 作者:bayaim 时间:2017-12-26 10:47:41 8 0删除编辑 忘记root密码------------------- ...
- go构建脚本ansible分发时出现的问题总结“non-zero return code”
背景介绍: 在Jenkins服务器配置go项目发布脚本,编译完成后,使用ansible分发到部署服务器上,然后将启动项目脚本start_coachcore.sh发布到目标服务器上,执行启动,目标服务器 ...
- Python—其它模块
系统监控模块psutil(第三方模块) psutil是一个跨平台的库,用于在Python中检索系统运行的进程和系统利用率(CPU,内存,磁盘,网络,传感器)的信息.它主要用于系统监控,性能分析,进程管 ...
- linux SSH设置
环境:centos7 一. ssh连接超时设置 (1)客户端设置(推荐) 客户端是windows系统 连接工具:SecureCRT 1.SecureCRT客户端->Options(选项)-> ...
- socket 与 websocket的区别
区别: socket并不是一个协议,而是抽象出来的一层,应用于应用层和传输控制层之间的一组接口, socket是传输控制层协议,websocket是应用层协议 websocket是什么样的协议,具有什 ...
- [C4W1] Convolutional Neural Networks - Foundations of Convolutional Neural Networks
第一周 卷积神经网络(Foundations of Convolutional Neural Networks) 计算机视觉(Computer vision) 计算机视觉是一个飞速发展的一个领域,这多 ...