2015 Fujian Provincial race

Source: Internet
Author: User

problem A Super Mobile Chargeraccept:217 submit:402 time limit:1000 mSec Memory limit:32768 KBproblem Description

While hits ACM Group finished their contest in Shanghai and are heading back Harbin, their train were delayed due to the Heav Y snow. Their mobile phones is all running out of battery very quick. Luckily, ZB have a super mobile charger that can charge all phones.

There is N people on the train, and the i-th phone have p[i] percentage of power, the Super mobile charger can charge at M ost M percentage of power.

Now ZB wants to know, at the most how many phones can is charged to full power. (Percent means full power.)

Input

The first line contains an integer T, meaning the number of the cases (1 <= T <= 50.).

For each test case, the first line contains integers n, M (1 <= n <= 100,0 <= M <= 10000), the second line Contains N integers p[i] (0 <= p[i] <=) meaning the percentage of power of the i-th phone.

Output

For each test case, output the answer of the question.

Sample Input2 3 10 100 99 90 3 1000 0 0 0Sample Output2 3

Problem: Water, that is, the train is late, there is a charge treasure, can punch a certain amount of electricity, ask how many people's mobile phone full power;

Code:

#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include < Cmath> #include <vector>using namespace std;const int inf=0x3f3f3f3f; #define MEM (x, y) memset (x,y,sizeof (×)) # Define SI (x) scanf ("%d", &x) #define PI (x) printf ("%d", x) #define T_T while (t--) const int Maxn=110;int A[maxn];int Main () {int t,n,m;si (T); T_t{si (N); Si (M); for (int i=0;i<n;i++) si (A[i]), A[i]=100-a[i];sort (a,a+n); int ans=0;for (int i=0;i<n;i++) {m-=a[ I];if (m<0) break;ans++;} printf ("%d\n", ans);} return 0;}

  

problem B Common tangentsaccept:191 submit:608 time limit:1000 mSec Memory limit:32768 KBproblem Description

The different circles can has at most four common tangents.

The picture below are an illustration of a and a circles with four common tangents.

Now given the center and radius of a circles, your job is to find how many common tangents between them.

Input

The first line contains an integer T, meaning the number of the cases (1 <= T <= 50.).

For each test case, there are one line contains six integers x1 (−100≤x1≤100), Y1 (−100≤y1≤100), R1 (0 < r1≤20 0), X2 (−100≤x2≤100), y2 (−100≤y2≤100), R2 (0 < r2≤200). Here (x1, y1) and (x2, y2) were the coordinates of the center of the first circle and second circle respectively, R1 is the Radius of the first circle and R2 is the radius of the second circle.

Output

For each test case, the output of the corresponding answer in one line.

If There is infinite number of tangents between the both circles then output-1.

Sample Input3 10 10 5 20 20 5 10 10 10 20 20 10 10 10 5 20 10 5Sample Output4 2 3

Solving: The number of straight lines tangent to two circles, consider the whole situation can be;

Code:

#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include < Cmath> #include <vector>using namespace std;const int inf=0x3f3f3f3f; #define MEM (x, y) memset (x,y,sizeof (×)) #  Define SI (x) scanf ("%d", &x) #define PI (x) printf ("%d", x) #define T_T while (t--) double js (int x,int y,int x1,int y1) {int Xx=x-x1,yy=y-y1;return sqrt (xx*xx+yy*yy);} int main () {int t,x1,x2,y1,y2,r1,r2;si (T); T_T{SCANF ("%d%d%d%d%d%d", &X1,&Y1,&R1,&X2,&Y2,&R2);d ouble d=js (x1,y1,x2,y2); if (d==0& &R1==R2) {puts ("-1"); continue;} if (D<abs (R1-R2)) {puts ("0"); continue;} if (D==abs (R1-R2)) {puts ("1"); continue;} if (r1+r2>d) {puts ("2"); continue;} if (D==R1+R2) {puts ("3"); continue;} if (r1+r2<d) {puts ("4"); continue;}} return 0;}

  

problem C knapsack problemaccept:83 submit:457 time limit:3000 mSec Memory limit:32768 KBproblem Description

Given a set of n items, each with a weight w[i] and a value v[i], determine a-to-choose the items into a knapsack so T Hat The total weight are less than or equal to a given limit B and the total value is as large as possible. Find the maximum total value. (Note that each item can is only chosen once).

Input

The first line contains the integer T indicating to the number of test cases.

For each test case, the first line contains the integers n and B.

Following n lines provide the information of each item.

The i-th line contains the weight w[i] and the value v[i] of the i-th item respectively.

1 <= Number of test cases <= 100

1 <= N <= 500

1 <= B, W[i] <= 1000000000

1 <= v[1]+v[2]+...+v[n] <= 5000

All the inputs is integers.

Output

For each test case, output the maximum value.

Sample Input1 5 15 12 4 2 2 1 1 4 10 1 2Sample Output15

The main question: give you a backpack, ask the value of the largest value in the backpack, because the quality is too large, the backpack as a value, that is, the same value put the minimum quality;

Code:

#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include < Cmath> #include <vector>using namespace std;const int inf=0x3f3f3f3f; #define MEM (x, y) memset (x,y,sizeof (×)) # Define SI (x) scanf ("%d", &x) #define PI (x) printf ("%d", x) #define T_T while (t--) typedef long LONG Ll;const int maxn=5050 ; LL bag[maxn];struct node{int w,v;}; Node Dt[maxn];int Main () {int t,n,m,v;si (T); T_t{si (n); SI (m); v=0;for (int i=0;i<n;i++) si (DT[I].W), Si (DT[I].V), V+=dt[i].v;mem (Bag,inf); bag[0]=0;for (int i=0;i<n;i++) {for ( int j=v;j>=dt[i].v;j--) {bag[j]=min (BAG[J],BAG[J-DT[I].V]+DT[I].W);}} for (int j=v;j>=0;j--) {if (bag[j]<=m) {printf ("%d\n", j); break;}}} return 0;}

  

problem E the longest straightaccept:71 submit:293 time limit:1000 mSec Memory limit:32768 KBproblem Description

ZB is playing a card game where the goal are to make straights. Each card of the deck has a number between 1 and m (including 1 and M). A straight is a sequence of cards with consecutive values. Values do not wrap around, so 1 does not come after M. In addition to regular cards, the deck also contains jokers. Each joker can is used as any valid number (between 1 and M, including 1 and M).

You'll be given N integers card[1]. CARD[N] Referring to the cards in your hand. Jokers is represented by zeros, and other cards is represented by their values. ZB wants to know the number of cards in the longest straight the can is formed using one or more cards from his hand.

Input

The first line contains an integer T, meaning the number of the cases.

For each test case:

The first line there is integers n and M in the first line (1 <= N, M <= 100000), and the second line contains N integers card[i] (0 <= card[i] <= M).

Output

For each test case, output a single integer in a line-the longest straight ZB can get.

Sample Input2 7 11 0 6 5 3 0 10 11 8 1000 100 100 100 101 100 99 97 103Sample Output5 3

Exercises

Let the longest continuous ascending sequence length, can be placed in any order, where 0 can represent any number between 1~m;

Discretization of the array, the elements of the element starting from 0, there is a previous value, did not appear to be the previous +1; Count 0 occurrences of the number of n0; then 0~m for each number of binary search, find the difference is n0 the maximum sequence length can be;

Code:

#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include < Cmath> #include <vector>using namespace std;const int inf=0x3f3f3f3f; #define MEM (x, y) memset (x,y,sizeof (×)) # Define SI (x) scanf ("%d", &x) #define PI (x) printf ("%d", x) #define T_T while (t--) const int Maxn=100010;int a[maxn],b[ Maxn];int erfen (int l,int r,int i,int x) {int Mid;while (l<=r) {mid= (l+r) >>1;if (b[mid]-b[i]>x) r=mid-1;else l =mid+1;} return l-i-1;} int main () {int t,n,m,x;si (T); T_t{si (N); Si (M); mem (a,0); int n0=0;for (int i=0;i<n;i++) {si (x); if (x==0) N0++;else a[x]=1;} b[0]=0;for (int i=1;i<=m;i++) {if (A[i]) B[i]=b[i-1];else b[i]=b[i-1]+1;} int ans=0;for (int i=0;i<=m;i++) {Ans=max (Ans,erfen (I,m,i,n0));} printf ("%d\n", ans);} return 0;}

  

problem J Runningmanaccept:131 submit:577 time limit:1000 mSec Memory limit:32768 KBproblem Description

ZB loves watching runningman! There ' s a game in Runningman called vs 100.

There is teams, each of many people. There is 3 rounds of fighting, in each round the and the teams send some people to fight. In each round, whichever team sends more people wins, and if the both teams send the same amount of people, Runningman team Wins. Each person can is sent out to only one round. The team wins 2 rounds win the whole game. Note, the arrangement of the fighter in three rounds must is decided before the whole game starts.

We know that there is N people on the Runningman team, and that there is M people on the opposite team. Now ZB wants to know whether there exists a arrangement of people for the Runningman team so it they can always win, no Matter how the opposite team arrange their people.

Input

The first line contains an integer T, meaning the number of the cases. 1 <= T <= 50.

For each test case, there's one line consists of the integers n and M. (1 <= N, M <= 10^9).

Output

For each test case, the Output "Yes" if there exists a arrangement of people so and the Runningman team can always win. "No" If there isn ' t such an arrangement. (without the quotation marks.)

Sample Input2 100 100) 200 100Sample OutputNo Yes

Puzzle: Two teams to play, the number of men running is N, the number of female team is m, each time two teams to select the number of games, three innings two wins, the number of teams to win, the numbers equal to the team wins, and asked whether the women team how to send people, running men to win;

It is easy to think, divide this number into three waves, running men to win, the three number of the smallest two must be greater than equal to half the number of female team;

Code:

#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include < Cmath> #include <vector>using namespace std;const int inf=0x3f3f3f3f; #define MEM (x, y) memset (x,y,sizeof (×)) # Define SI (x) scanf ("%d", &x) #define PI (x) printf ("%d", x) #define T_T while (t--) int main () {int t,n,m,x;si (T); T_t{si (N), SI (M), if (m&1) x=3* (M/2), Else x=3* (M/2) -1;if (n>=x) puts ("Yes"), Else puts ("No"); return 0;}

  

2015 Fujian Provincial race

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.