Opposite Task
来源:互联网 发布:网络管理和信息安全 编辑:程序博客网 时间:2024/06/06 06:41
This problem gives you a flavor the concept of special judge. That means the judge is smart enough to verify your code even though it may print different results. In this problem you are asked to find the opposite task of the previous problem.
To be specific, I have two computers where I stored my problems. Now I know the total number of problems is n. And there are no duplicate problems and there can be at most 10 problems in each computer. You have to find the number of problems in each of the computers.
Since there can be multiple solutions. Any valid solution will do.
Input starts with an integer T (≤ 25), denoting the number of test cases.
Each case starts with a line containing an integer n (0 ≤ n ≤ 20) denoting the total number of problems.
For each case, print the number of problems stored in each computer in a single line. A single space should separate the non-negative integers.
3
10
7
7
0 10
0 7
1 6
分析:题目读了好久才明白,就是求解一个数的和的可能的组合,两个注意点:一、每个数最大10,二、因为对于任何的组合都可以,所以要产生随机数,随机数的大小和每个数组合的个数有关。
上代码:
import java.util.*; public class Main{ static Scanner in=new Scanner(System.in); static List<solu> st = new ArrayList<solu>(); //计算组合的种类 static void solve(int n,int a){ int b; while(a!=n/2+1){ b = n-a; solu s =new solu(); s.n1 = a; s.n2 = b; st.add(s); a++; } } public static void main(String args[]){ int k=in.nextInt(); //当n大于10的时候,组合的个数,直接算了方便取 int[] ran = {0,5,5,4,4,3,3,2,2,1,1}; while(k-->0){ st.clear(); int n = in.nextInt(); int a , r; if(n<=10){ a = 0; solve(n,a); r = (int) (Math.random()*(n/2+1)); } else{ a = n - 10; solve(n,a); r = (int) (Math.random()*ran[n-10]); } //任何组合都可以,随便取一个即可 System.out.println(st.get(r).n1+" "+st.get(r).n2); } }} class solu{ int n1; int n2;}
- Opposite Task
- LightOJ - 1001 Opposite Task
- LightOJ-1001-Opposite Task
- LightOj 1001 - Opposite Task (数值和的拆分)
- Detect if two integers have opposite signs
- Detect if two integers have opposite signs
- TASK
- Task
- Task
- TASK
- task
- Task
- task
- Task,
- task
- Task
- task
- task
- c++智能指针那些事
- Jenkins+Github+webhook step by step
- AJAX(五)--聊天室
- HTML学习之路-3 HTML标签
- leetcode.array--27. Remove Element
- Opposite Task
- DQL-数据查询
- 532. K-diff Pairs in an Array
- 后缀自动机 重复旋律 6(长度为K的旋律中出现次数最多的旋律的出现次数)
- 1091. Acute Stroke (30)
- Material 组件 list
- C#实现winform天气预报
- Android Gradle plugin版本和Gradle版本
- 【Android系列】View的绘制之layout过程