A.有理数
签到题:直接用floor函数就行了,详细看代码
#define debug #include<stdio.h> #include<math.h> #include<cmath> #include<queue> #include<stack> #include<string> #include<cstring> #include<string.h> #include<algorithm> #include<iostream> #include<vector> #include<functional> #include<iomanip> #include<map> #include<set> #define f first #define s second #define pb push_back using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll>PLL; typedef pair<int,ll>Pil; const ll INF = 0x3f3f3f3f; const double inf=1e8+100; const double eps=1e-8; const ll maxn =1e3+200; const int N = 1e4+10; const ll mod=1e9+7; //define //--solve void solve() { int i,j,tt=1; cin>>tt; while(tt--){ ll p,q; ll tmp; cin>>p>>q; if(p%q==0){ tmp=floor(p*1.0/q)-1; } else tmp=floor(p*1.0/q); cout<<tmp<<endl; } } int main() { ios_base::sync_with_stdio(false); #ifdef debug freopen("in.txt", "r", stdin); // freopen("out.txt","w",stdout); #endif cin.tie(0); cout.tie(0); solve(); /* #ifdef debug fclose(stdin); fclose(stdout); system("out.txt"); #endif */ return 0; }
B。硬币,实际上50,10都是有5的倍数,所以可以直接吧50,10元的看成是数个5元构成硬币,那问题就容易了,假设一个物品要v元,remain=v%5,就为剩下的还要给少个硬币才能凑够买一个v元物品,然后k=5-remain,这这个k其实就是找回的1元硬币数,详细看代码
#define debug #include<stdio.h> #include<math.h> #include<cmath> #include<queue> #include<stack> #include<string> #include<cstring> #include<string.h> #include<algorithm> #include<iostream> #include<vector> #include<functional> #include<iomanip> #include<map> #include<set> #define f first #define s second #define pb push_back using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll>PLL; typedef pair<int,ll>Pil; const ll INF = 0x3f3f3f3f; const double inf=1e8+100; const double eps=1e-8; const ll maxn =1e3+200; const int N = 1e4+10; const ll mod=1e9+7; //define ll c[maxn]; // ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); } //--solve void solve() { int i,j,tt=1; cin>>tt; ll c1,c2,c4,c3,v; while(tt--){ ll ans=0ll,sum=0; cin>>c1>>c2>>c3>>c4>>v; sum=c2*5+c3*10+c4*50; ll remain=v%5; ll k=0ll; if(remain){ k=5-remain; v+=k; } ans=k*(sum/v)+c1; cout<<ans<<endl; } } int main() { ios_base::sync_with_stdio(false); #ifdef debug freopen("in.txt", "r", stdin); // freopen("out.txt","w",stdout); #endif cin.tie(0); cout.tie(0); solve(); /* #ifdef debug fclose(stdin); fclose(stdout); system("out.txt"); #endif */ return 0; }