UESTC 1647 Battery Charging(규칙 시뮬레이션 찾기)
Description
Recently, qbwj bought a powerful cellphone which performs even better than most computers. He spent lots of time on it. However, this cellphone has a very strange feature which confused qbwj. There is a battery with infinite capacity in the cellphone. On each day, qbwj has three choices: use the cellphone, charge the battery or do nothing. He cannot do using and charging on the same day. Charging on the kth day adds k units of power to the battery. If qbwj chooses to use the cellphone on the kth day, it would consume k units of power. Note that qbwj can choose to use the cellphone if and only if there are enough units of power in the battery. Despite of the strengths of the cellphone, qbwj couldn't suffer it any more. So he decides to sell it at the end of Tth day. Today is the Sth day and the battery is empty now. He wants to know how many days at maximum he can use the cellphone before selling it out. Note that qbwj can still choose to use the cellphone on both the Sth day and Tth day.
Input
The first line of the input will be an integer N (N <= 10000) indicating the number of cases. For each test case, two integers are given on a single line: S T. 1 <= S <= T <= 108.
Output
Print "Case #k: d"in a single line for each test case, in which k represents the case number which starts from 1, and d is the answer.
Sample Input
3 3 6 3 9 1 100000
Sample Output
Case #1: 1 Case #2: 3 Case #3: 49994
Hint
For the first sample, we charge the cellphone on the 3rd, 4th, 5th day and use it on the 6th day.
Source
10th UESTC Programming Contest Final
분석: 간단한 욕심, 분명히 배터리를 사용할 수 있는 것은 1, 이후에 사용하면 더 많은 전기를 소비하기 때문이다.2. 이후 충전은 현재 충전보다 더 많은 전력을 얻는다.S일에는 배터리가 방전되고 충전이 끝나면 S의 배터리가 남습니다. S+1일에는 배터리가 부족하기 때문에 충전이 필요합니다. 충전이 끝나면 2*S+1의 배터리가 남습니다. S+2일에는 배터리를 사용하고 다 쓰면 S-1의 배터리가 남습니다. 나중에 이런 절차를 반복합니다. 즉, 하루 충전하고 하루를 사용합니다.이런 절차를 한 번씩 진행할 때마다 남은 전력량을 1씩 줄인다.그래서 S의 전량은 S회 이런 절차를 진행할 수 있고 S일을 사용했다.3*S일, 남은 전력량은 0입니다.그리고 3*S+1일은 같은 문제입니다.매번 3배의 성장을 시뮬레이션하면 되기 때문이다.
내 코드:
#include
#include
#include
using namespace std;
int main()
{
int t,cas=1,k,a,b,ans;
scanf("%d",&t);
while(t--)
{
ans=0;
scanf("%d%d",&a,&b);
while(a
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
잃어버린 괄호일단 기본적으로 1]string tmp를 통해서 전체문자열에서 특정부분 합치기 2] + 나 - 해당되는 경우에 flag변수를 통해서, flag가 1인경우에는 빼고, 0인 경우에는 더한다. 3]연산자가 연속해서 나타나...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.