本文已参与「新人创作礼」活动,一起开启掘金创作之路。
@TOC
Codeforces Round #734 (Div. 3)-A. Polycarp and Coins
传送门 Time Limit: 1 second Memory Limit: 256 megabytes
Problem Description
Polycarp must pay exactly burles at the checkout. He has coins of two nominal values: burle and burles. Polycarp likes both kinds of coins equally. So he doesn't want to pay with more coins of one type than with the other.
Thus, Polycarp wants to minimize the difference between the count of coins of burle and burles being used. Help him by determining two non-negative integer values and which are the number of coins of burle and burles, respectively, so that the total value of that number of coins is exactly (i. e. ), and the absolute value of the difference between and is as little as possible (i. e. you must minimize ).
Input
The first line contains one integer () — the number of test cases. Then test cases follow.
Each test case consists of one line. This line contains one integer () — the number of burles to be paid by Polycarp.
Output
For each test case, output a separate line containing two integers and () separated by a space where is the number of coins of burle and is the number of coins of burles. If there are multiple optimal solutions, print any one.
Sample Input
6
1000
30
1
32
1000000000
5
Sample Onput
334 333
10 10
1 0
10 11
333333334 333333333
1 2
Note
The answer for the first test case is "334 333". The sum of the nominal values of all coins is , whereas . One can't get the better value because if , then and , but then the value of isn't an integer.
The answer for the second test case is "10 10". The sum of the nominal values is and , whereas there's no number having an absolute value less than .
题目大意
有两种钞票,面值分别是1元和2元。 买一个物品,想让使用两种钞票的数量的绝对值只差最小,请问两种钞票分别用几张。
解题思路
一张1元+一张2元是3元。先看金额中有多少个3,这些3都用相等数量的两种钞票构成。 多余的钱只能是0,1,2。如果是0就正好,是1就再来一张1元的,是2就再来一张2元的。
AC代码
#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
int main()
{
int N;
cin>>N;
while(N--)
{
int n;
cin>>n;
int t=n/3;
int t2=t;
int s=n%3;
if(s==0);
else if(s==1)t++;
else if(s==2)t2++;
printf("%d %d\n",t,t2);
}
return 0;
}
同步发文于我的CSDN,原创不易,转载请附上原文链接哦~
Tisfy:letmefly.blog.csdn.net/article/det…