有多行,每行两个整数N(10<=N<=50), K(1<=K<=20)
针对每组数据,如果在第21年或者之前就能买下这套房子,则输出一个整数M,表示最早需要在第M年能买下,否则输出Impossible,输出需要换行
50 10 40 10 40 8
8 Impossible 10
#include <iostream> #include<vector> using namespace std; int main() { double n, k; while (cin >> n >> k) { int cnt = 1; double sum = n; double price = 200; bool sta = true; while (sum < price) { sum += n; price = price*(1 + k / 100); cnt++; if (cnt > 21) { sta = false; break; } } if (sta == true) cout << cnt << endl; else cout << "Impossible" << endl; } return 0; }
#include<stdio.h> int main(){ int n,k; while(scanf("%d%d",&n,&k)!=EOF) { int total=200,sum=n,i; if(sum>=total) {printf("1\n"); continue;}//第一年就成功 for(i=2;i<22;i++) { total*=1+k*0.01;//在当前基础上上涨,而不是一直在200的基础上 sum+=n; if(sum>=total) break; } if(i<=21) printf("%d\n",i); else printf("Impossible\n"); } }
#include<iostream> using namespace std; int main(){ int n,k; while(cin>>n>>k){ int total=200; int money=n; int year=0,judge=0; for(int i=2;i<22;i++){ total*=1+(double)k/100; money+=n; if(money>=total){ year=i; judge=1; break; } } if(judge==1) cout<<year<<endl; else cout<<"Impossible"<<endl; } }
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ double target = 200.0; int n = sc.nextInt(); int k = sc.nextInt(); int i; for(i=2;i<=21;i++){ target = target*(k+100)/100; if(n*i >= target){ System.out.println(i); break; } } if(i>21){ System.out.println("Impossible"); } } } }
while True: try: string = raw_input().strip().split() salary = int(string[0])*1.00 num = salary k = int(string[1])*1.00 payment = 200.00 i = 1 while num < payment and i <= 21: num += salary payment *= (k/100+1.0) i += 1 print i if i<=21 else "Impossible" except: break
#include<bits/stdc++.h> using namespace std; #define LL long long int main(){ int n,k; while(cin >> n >> k){ double max = n * 1.0 / (k * 1.0 / 100); //cout<<" "<<max<<endl; int price = 200; int money = n; int y = 1; while(price < max){ if(money >= price){ cout<<y<<endl; break; } y ++; money += n; price *= (1 + k * 1.0 / 100); //cout<<"y = "<<y<<"\tmoney = "<<money<<"\t price = "<<price<<endl; } if(price >= max){ cout<<"Impossible\n"; } } return 0; }
def buyhoues(n, k): price = 200 flag = 0 for i in range(1, 24): if i == 1: continue else: price = price * (1 + k / 100) s = n*i if price <= s and i < 21: flag = 1 break if flag == 1: print(i) else: print('Impossible') while True: try: N, K = map(int, input().split()) buyhoues(N, K) except: break
#include <cmath> #include <iostream> using namespace std; int main() { int n, k; while (cin >> n >> k) { int m = 1; double money = 0, cost = 200; //程序员的现有资金和房子的价格 while (m <= 21) { money += n; //程序员赚钱 if (money >= cost) { break; } cost *= 1 + k / 100.0; //房价上涨 cost = floor(cost * 100 + 0.5) / 100; //保留2位小数 m++; //进入下一年 } m <= 21 ? cout << m << endl : cout << "Impossible" << endl; } return 0; }
#include <cstdio> int main(){ int n,k; while(scanf("%d %d",&n,&k) != EOF){ int money = 0; float price = 200; bool flag = false; for(int i = 0; i <= 20; ++i){ if(money >= price){ //买得起房 printf("%d\n",i); flag = true; break; }else{ //今年买不起。接着攒钱,房子涨价 money += n; if(i == 0) continue; //第零年房价不增 price += price*k/100; } } if(flag == false){ printf("Impossible\n"); } } return 0; }
#include <iostream> using namespace std; int main() { double n, k; double sum = 0; //总工资 double price = 200; while (cin >> n >> k) { k = k / 100; //k转换为百分比 int i; for (i = 1; i <= 21; i++) { sum = i * n; if (i > 1) price = price * (1 + k); if (sum >= price) { cout << i << endl; break; } } if (i == 22) cout << "Impossible" << endl; sum = 0; price = 200; } }
#include <cstdio> #include <iostream> using namespace std; int main() { double n,k; while(scanf("%lf%lf",&n,&k)!=-1){ int m=1; double house=200,wallet=n; while(m<=21){ m++; house*=1+k/100; wallet+=n; if(wallet>=house){ cout<<m<<endl; break; } } if(m>21){ cout<<"Impossible"<<endl; } } }
#include<iostream> using namespace std; int main(){ int N, K; while(cin >> N >> K){ double price = 200; if(N >= price) {cout << 1 << endl; continue;} int year = 2; int deposit = N; double interval = price - deposit; for(;;year++){ price *= (1 + K * 0.01); deposit += N; double new_interval = price - deposit; if(new_interval > interval) {cout << "Impossible" << endl; break;} interval = new_interval; if(interval <= 0) { cout << year << endl; break;} } } }
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int n, k, year; //n-年薪 k-房价涨幅 存款年数 while (scanf("%d %d", &n, &k) != EOF) { double total_save = n, value = 200; //value-房价 for (year = 1; total_save < value && n > value * k / 100.0 ; year++) { total_save += n; value *= (1.0 + k / 100.0); } if (total_save >= value) { printf("%d\n", year); } else { printf("Impossible\n"); } } }