f373 - 週年慶 Anniversary
題目描述
題目描述的是一個週年慶的活動,根據消費金額給予不同的折扣。如果消費金額大於等於 1000,則可以獲得 100 元的折扣;如果消費金額大於等於 2000,則可以獲得 200 元的折扣。題目要求計算在兩種折扣方案下,可以獲得的最大折扣金額,並輸出折扣金額和對應的方案編號(0 或 1)。
解題思路
題目要求計算兩種折扣方案(100 元和 200 元)中,可以獲得的最大折扣金額。
首先,計算使用 100 元折扣方案可以獲得的折扣金額 a,即 n - (n / 2000) * 200。
然後,計算使用 100 元折扣方案可以獲得的折扣金額 b,即 n - (n / 1000) * 100。
最後,比較 a 和 b 的大小,如果 a 大於等於 b,則輸出 a 和 0;否則,輸出 b 和 1。
複雜度分析
- 時間複雜度: O(1)
- 空間複雜度: O(1)
程式碼
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <stdio.h>
inline int read(){
int a(0);
char c('0');
while(c>='0'){
a=(a<<3)+(a<<1)+c-'0';
c=getchar_unlocked();
}
return a;
}
inline void write(int x) {
if(x==0)
putchar_unlocked('0');
else{
int stk[9],*ptr(&stk[0]);
while(x){*ptr=x%10;x/=10;++ptr;}
while(--ptr>=(&stk[0])){putchar_unlocked(*ptr+'0');}
}
}
int main(){
int n,a,b;
n=read();
b=n-(n/1000*100);
a=n-(n/2000*200);
if(a<=b){
write(a);
putchar_unlocked(' ');
putchar_unlocked('0');
}
else{
write(b);
putchar_unlocked(' ');
putchar_unlocked('1');
}
}