1. 程式人生 > >Wannafly交流賽1(施工中)

Wannafly交流賽1(施工中)

fin ase 代碼 namespace pre nbsp stdio.h false rst

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;
}

  

Wannafly交流賽1(施工中)