The sixth annual Blue Bridge Cup software competition Group A preliminary

Source: Internet
Author: User
Tags cmath

Here is my personal answer, welcome to the discussion.
And the last two questions to get positive solutions.
Equation Integer Solution


Equation: a^2 + b^2 + c^2 = 1000
(or see "Figure 1.jpg")
Does this equation have an integer solution? Yes: A,b,c=6,8,30 is a set of solutions.
Can you figure out a different set of solutions?
a,b,c=10,18,24


Please fill in the smallest number in the solution.
10

Note: You should submit an integer, do not fill in any superfluous content or descriptive text.

Code:

#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath > #include <vector> #include <algorithm> #include <map>const int N = 1001;using namespace Std;int Main () {int x,y,z;for (int i=1;i<=sqrt (n); i++) {for (int. j=1;j<=sqrt (n); j + +) {for (int k = 1;K<=SQRT (n); k++) {if (I*i + j *j + k*k==1000) {printf ("%d%d%d\n", i,j,k);}}} return 0;}




Galaxy bomb


In the vast space of the X galaxy, many X-star man-made "bombs" were floated to serve as signposts in the universe.
Each bomb can be set to explode after a few days.
For example: The Alpha bomb was placed on January 1, 2015 and timed for 15 days, then it exploded on January 16, 2015.
There is a beta bomb, placed on November 9, 2014, timed for 1000 days, please calculate the exact date it exploded.


Please fill in the date in the format YYYY-MM-DD the 4-bit year 2-digit month 2-bit date. For example: 2015-02-19
Please write strictly in the format. No other text or symbols can appear.
2017-08-05

#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath > #include <vector> #include <algorithm> #include <map>const int N = 1001;using namespace Std;int Main () {int mou[20] = {0,31,28,31,30,31,30,31,31,30,31,30,31};int T = 0;int year = 2014,m = 11,day = 9;while (t<=1000) {int P s = 0;if (M = = 2 && year%4==0 && Year% 400!=0) {PS = 1;} while (day<= (Mou[m]+ps)) {day++;t++;if (t>=1000), break;} if (t>=1000) Break;day = 1;m++;if (m==13) {year++;m = 1;} printf ("%d%d%d\n", year,m,day,t);} printf ("%d%d%d\n", year,m,day); return 0;}



Wonderful numbers.


Xiao Ming found a wonderful figure. Its square and cubic meters just take the 0~9 10 numbers each and use them only once.
Can you guess how much this number is?


Please fill in this number, do not fill in any superfluous content.
69

#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath > #include <vector> #include <algorithm> #include <map>const int N = 1001;using namespace Std;bool Solve (int a,int b) {int ok[20];memset (ok,0,sizeof (OK)); while (a) {ok[a%10]++;a/=10;} while (b) {ok[b%10]++;b/=10;} BOOL flag = true;for (int i=0;i<10;i++) {if (ok[i]! = 1) {flag = False;break;}} return flag;} int main () {for (int i=1;; i++) {int xx = I*i;int xxx = i*i*i;if (Solve (xx,xxx)) {printf ("%d\n", I); break;}} return 0;}




In-grid output


The Stringingrid function prints the specified string in a grid of a specified size.
Requires the string to be centered in a horizontal, vertical, two direction.
If the string is too long, it is truncated.
If you can't just center it, you can do it slightly to the left or to a point.


The following program implements this logic, please fill in the missing code in the underlined section.

#include <stdio.h> #include <string.h>void stringingrid (int width, int height, const char* s) {int I,k;char buf [1000];strcpy (buf, s); if (strlen (s) >width-2) buf[width-2]=0;printf ("+"); for (i=0;i<width-2;i++) printf ("-"); printf ("+\n"); for (k=1; k< (height-1)/2;k++) {printf ("|"); for (i=0;i<width-2;i++) printf ("");p rintf ("|\n");} printf ("|"); printf ("%*s%s%*s", (Width-strlen (BUF)-2)/2, "", Buf, (Width-strlen (BUF)-2)/2+ (Width-strlen (BUF)-2)%2, "");  Fill in the blanks with          printf ("|\n"); for (k= (height-1)/2+1; k



Number of card types


Xiao Ming was hijacked to X Vegas and was forced to play cards with 3 other people.
A deck of poker (minus the size of ace, a total of 52), evenly distributed to 4 people, each 13 Zhang.
At this time, Xiao Ming's brain suddenly emerged a problem:
If you do not consider the suit, only consider the points, also do not consider the order of the cards you get, you can get the initial combination of the total number of types?


Please fill in this integer, do not fill in any superfluous content or descriptive text.

13*13*13*13 * 12*12*12*12 * 11*11*11*11 * 10 =
86709989583360 (Feeling a little wrong, ask Daniel for advice)



Bracelet Style


Xiao Ming has 3 red coral, 4 white coral, 5 yellow agate.
He wanted to use them in a circle as a bracelet and give it to his girlfriend.
Now xiaoming would like to know: if you consider the bracelet can be rotated or flipped, how many different combinations can be?


Please submit the integer. Do not fill in any superfluous content or descriptive text.
27719

#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath > #include <vector> #include <algorithm> #include <map>const int N = 1001;using namespace Std;typedef __int64 ll;map<ll,int> m;int cnt[20] = {1,1,1,2,2,2,2,3,3,3,3,3};bool solve (int a[]) {for (int i=0;i<12;i++) {LL TMP = 0;for (int j = i;j<12;j++) {TMP = TMP *10 + a[j];} for (int j = 0;j<i;j++) TMP = tmp *10 + a[j];//printf ("%i64d\n", TMP), if (M[tmp]) {}else{m[tmp] = 1;return true;}} LL tmp = 0;for (int i=11;i>=0;i--) TMP = tmp *10 + a[i];if (m[tmp]) {}else{m[tmp] = 1;return true;} return false;}  int main () {int ans = 0;//solve (CNT), while (Next_permutation (cnt,cnt+12)) {LL TMP = 0;for (int i=0;i<12;i++) {TMP = TMP * 10 + cnt[i];} printf ("%i64d\n", TMP), if (Solve (CNT)) {ans++;}} printf ("%d\n", ans); return 0;}



Beverage Redemption


A promotional offer is being held at the Lok Yang Sheep beverage factory. The C-type beverage, with 3 caps can be replaced by a bottle of C-type beverage, and can be recycled (but not allowed to borrow or credit).


Please calculate, if Xiao Ming does not waste the bottle cap, as far as possible to participate in activities, then, for his initial purchase of the N bottle of drinks, finally he can drink a total number of bottles of drinks.


Input: An integer n representing the number of drinks to start buying (0<n<10000)
Output: An integer representing the number of drinks actually obtained


For example:
User input:
100
The program should output:
149


User input:
101
The program should output:
151




Resource contract:
Peak memory Consumption < 256M
CPU Consumption < 1000ms
#include <algorithm> #include <map>const int N = 1001;using namespace Std;int main () {int n;while (~scanf ("%d", &n)) {int ans = N,tmp = N;while (tmp>=3) {int ps = Tmp;ans+=ps/3;tmp = ps%3 + ps/3;} printf ("%d\n", ans);} return 0;}




Base Dice


Gambling San ATM in the old age infatuated with the dice, is the dice one base on the other top, not crooked, to base solutionkeys column body.
After a long observation, ATM found the secret of stabilizing the dice: Some of the number of the surface will be mutually exclusive!
Let's start by standardizing the dice: 1 opposite is 4,2 opposite is 5,3 opposite is 6.
If there is an M-group mutex, the two-digit face of each group clings to one another, and the dice cannot stabilize the base.
The ATM wants to calculate how many different possible ways to base the dice.
The two types of dice are the same, and the corresponding numbers of the dice corresponding to the height of the two methods are the same.
Because the number of scenarios may be too large, output modulo 10^9 + 7 results.


Do not underestimate the number of ATM dice Oh ~


"Input Format"
First row of two integers n m
n indicates the number of dice
The next m line, two integers a b per line, indicates that A and B numbers cannot be glued together.


"Output Format"
A row of a number that represents the result of the answer modulo 10^9 + 7.


"Sample Input"
2 1
1 2


"Sample Output"
544


"Data Range"
For 30% data: N <= 5
For 60% data: N <= 100
For 100% data: 0 < n <= 10^9, M <= 36


This topic looks at the headache, the situation is too many! It's supposed to be a classified discussion.





Post-disaster reconstruction


Pear City A total of n (<=50000) settlements, between the settlements have M (<=200000) two-way road connected. These settlements can be reached by two-way roads between 22. This has continued until recently, when a serious earthquake destroyed all M roads.
After the quake, Pear intends to repair some of these roads and to repair the time required for the route I roads need pi. However, Pear does not intend to allow all points to be connected, but instead chooses some special points to connect them.
Pear has a Q (<=50000) query, and each time he asks, he will select all numbers in [L,r], and the number mod K = C points, repair some roads to make them connected. As all roads are repaired at the same time, the time to complete the repairs depends on the longest route, i.e. the maximum value of the PI in the road involved.


Can you help pear calculate the minimum time to spend on each query? The inquiry here is independent, that is, the repair plan in the last inquiry was not put into action.


"Input Format"
The first line of three positive integers n, M, Q, meaning title face is described.
Next M-line, three positive integers per line XI, Yi, Pi, represents a two-way road connecting Xi and Yi, repairing the time required for Pi. There may be self-loops and there may be heavy edges. 1<=pi<=1000000.


Next Q line, four positive integers per line Li, Ri, Ki, Ci, indicating that the point of this inquiry is the [Li,ri] interval of all the numbered mod ki=ci points. Ensure that there are at least two points involved in the inquiry.


"Output Format"
The output Q line, a positive integer per line, indicates the answer to the corresponding query.


"Sample Input"
7 10 4
1 3 10
2 6 9
4 1 5
3 7 4
3 6 9
1 5 8
2 7 4
3 2 10
1 7 6
7 6 9
1 7 1 0
1 7 3 1
2 5 1 0
3 7 2 1


"Sample Output"
9
6
8
8


"Data Range"
For 20% of data, n,m,q<=30
For 40% of data, n,m,q<=2000
For 100% of data, n<=50000,m<=2*10^5,q<=50000. Pi<=10^6. Li,ri,ki are within the scope of [1,n], ci in [0, corresponding to the Ki of Inquiry).


Small data is said to be the smallest spanning tree solvable, big data should betree chain split, just read the topic


The sixth annual Blue Bridge Cup software competition Group A preliminary

Related Article

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.