每组测试数据占1行,每行一个正整数a (a < 32768)
输出包含n行,每行对应一个输入,包含两个正整数,第一个是最少的动物数,第二个是最多的动物数,两个正整数用一个空格分开 如果没有满足要求的答案,则输出两个0。
2 3 20
1 1 0 0 5 10
#include <iostream> #include <cstdio> #include <math.h> using namespace std; const int N = 100000; int prime[N] = { 0 }; int MOST(int n) { int sum = n / 2; return sum; } int Less(int n) { int sum=0; if (n % 4 == 0) { sum = n / 4; } else { sum = n / 4 + 1; } return sum; } int main() { int a; while (cin>>a) { if (a % 2 != 0) { cout << "0 0"; break; } else { cout<<Less(a)<<" "; cout<<MOST(a); } } }
#include<cstdio> #include<iostream> using namespace std; int main(){ int a; while(scanf("%d",&a)!=EOF){ int max,min; max=min=0; if(a%2==0){ max=a/2; min=a/4+(a%4)/2; } cout<<min<<' '<<max<<endl; } return 0; }
#include<stdio.h> int main() { int sum; scanf("%d",&sum); if(sum==2)//最多最少都是一只鸡 { printf("1 1"); return 0; } if(sum%2!=0) printf("0 0\n"); else//是2的倍数 { if(sum%4==0)//是4的倍数 printf("%d %d",sum/4,sum/2); else//仅仅是2的倍数,不是4的倍数 printf("%d %d",sum/4+1,sum/2);//加一是因为不满足都是兔子但是剩下了两条腿所以大多数是兔子加一只鸡 } return 0; }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ int a = scanner.nextInt(); if (a%2!=0||a<=1)System.out.println("0 0"); else { int min = a/4+(a%4)/2; int max = a/2; System.out.println(min+" "+max); } } } }
#include<iostream> using namespace std; int main(){ int a[6]; for(int i=0;i<6;i++) cin>>a[i]; int total=0; for(int i=1;i<6;i++){ if(a[i]<a[0]) total+=a[i]; } cout<<total<<endl; }
#include<iostream> #include<cstdio> using namespace std; int main() { int t; cin >> t; while(t--) { int min = 0; int max = 0; int j, t; int a; cin >> a; // 求 最少 t = a/4; j = (a - t*4)/2; if(a == t*4+j*2) { min = j+t; } // 求 最多 j = a/2; t = (a - j*2)/4; if(a == j*2+t*4) { max = j+t; } cout << min << " " << max << endl; } return 0; }
#include <stdio.h> int main() { int a; int least, most; while(scanf("%d", &a)!=EOF) { if(a%2==1) { printf("0 0\n"); continue; } a=a/2;//总腿数减半,同时假设鸡1条腿,兔2条腿 most=a;//全是鸡 if(a%2==0) least=a/2;//全是兔 else least=a/2+1;//有一只鸡,剩下全是兔 printf("%d %d\n", least, most); } return 0; }
#include <cstdio> #include <stdlib.h> #include <iostream> using namespace std; int mini(int n); int maxs(int n); //Chicken rabbit cage int main() { int n; while (scanf("%d", &n) != EOF) { int minn = 0; int maxx = 0; //只有偶数才有解 if (n % 2 == 0) { //求最小动物数量 minn = n / 4 + (n % 4) / 2; //求最大动物数量 maxx = n / 2; } printf("%d %d\n", minn, maxx); } return 0; }
#include <iostream> using namespace std; int main() { int n,minn,maxn; while(cin >> n){ minn = 0,maxn=0; if(n%2!=0){ cout << 0 << " " << 0<<endl; }else{ maxn = n/2; int temp = n/4; int remain = n%4; minn=temp+remain/2; cout << minn<<" "<<maxn<<endl; } } return 0; }
#include <iostream> using namespace std; int main() { int a; while(cin>>a){ a%2==0?cout<<a/4+a%4/2<<" "<<a/2<<endl:cout<<"0 0"<<endl; } return 0; }
def chick(a): flag = 0 arr = [] for i in range(a): for j in range(a): if 2 * i + j * 4 == a: flag = 1 k = i + j arr.append(k) #print("%d %d"%(i, j)) #print("%d %d"%(min(arr), max(arr))) if flag == 0: print("%d %d"%(0, 0)) else: print("%d %d"%(min(arr), max(arr))) while True: try: a = int(input()) chick(a) except: break
#include <iostream> using namespace std; int main() { int a; while (cin >> a) { // 注意 while 处理多个 case if (a % 2 != 0) cout << "0 0" << endl; else if (a % 4 == 0) cout << a / 4 << ' ' << a / 2 << endl; else cout << a / 4 + 1 << ' ' << a / 2 << endl; } }