15.4.19 第四届华中区程序设计邀请赛暨武汉大学第十三届校赛 网络预选赛
Total Submit: 349 Accepted: 73 Special Judge: No
Here is a circle sequence S of length n, and you can choose a position and remove the number on it.
After that,you will get a integer. More formally,you choose a number x( 1<=x<=n ),then you will get the integer Rx = Sx+1……SnS1S2…..Sx-1.
The problem is which number x you choose will get the k-th smallest Rx.
If there are more than one answer,choose the one with the smallest x.
Next line contains a number of length n. Each position corresponds to a number of 1-9.
6228814462
10 4
9282777691
7
Total Submit: 445 Accepted: 168 Special Judge: No
Here are n numbers.
You have a magic : first , you choose a interval [l,r],and then each Si(l<=i<=r) will be ( 10 – Si ) % 10.
You can use the magic at most once to make sum of all the numbers to be maximum.
What is the maximum sum you can get?
Next line contains n numbers without space-separated. Each position corresponds to a number of 0-9.
3775053808
10
2580294019
10
4701956095
50
54
#include<cstdio> #include<iostream> #include<cmath> #include<cstring> #include<queue> #include<stack> #include<vector> #include<stdlib.h> #include<algorithm> using namespace std; const int MAXN=1000000+5; const int INF=0x3f3f3f3f; char str[MAXN]; int a[MAXN],b[MAXN],c[MAXN],dp[MAXN]; int main() { int n; while(scanf("%d",&n)!=EOF) { memset(dp,0,sizeof(dp)); scanf("%s",str+1); int len=strlen(str+1),sum=0; for(int i=1;i<=len;i++)//将数组转变做差得到相差的数字序列 { a[i]=str[i]-'0'; b[i]=(10-a[i])%10; c[i]=b[i]-a[i]; sum+=a[i]; } int maxn=-INF; for(int i=1;i<=n;i++)//求最大连续子序列 { if(dp[i-1]+c[i]<c[i]) dp[i]=c[i]; else dp[i]=dp[i-1]+c[i]; if(dp[i]>maxn) maxn=dp[i]; } printf("%d\n",sum+maxn); } return 0; }
Total Submit: 383 Accepted: 82 Special Judge: No
You are given a graph with N nodes and M edges.
Then every time you are required to add an additional edge with weight Wi connecting the node Ai and Bi in the graph, and then calculate the sum of the edges’ weight of the Minimum Spanning Tree of the current graph. You’ll be asked to complete the mission for Q times.
The Minimum Spanning Tree of a graph is defined to be a set of N - 1 edges which connects all the N nodes of the graph and the sum of all the edges is as small as possible.
It's guaranteed that the graph is connected.
The following M lines contains three numbers Ai , Bi and Wi.( 1 ≤ Ai, Bi ≤ 1000, 1 ≤ Wi≤ 100000).
The last Q lines of this case contains three numbers Ai , Bi and Wi. ( 1 <= Ai, Bi <= 1000, 1 ≤ Wi≤ 100000 ).
2 1 8
3 1 4
1 2 6
1 2 4
2 3 1
1 1 4
3 3 3
2 1 7
3 2 8
3 3 6
1 3 3
2 2 3
2 2 3
5
5
10
10
10
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<queue> #include<vector> #include<ctype.h> #define LL __int64 using namespace std; const int MAXN=100000+5; const int MAX=1000+5; struct node { int s; int e; int val; bool operator<(const node A) const { return val < A.val; } } a[MAXN],b[MAX]; int p[MAX],ans,cnt; int n,m,q; int findfa(int x) { p[x]==x?x:p[x]=findfa(p[x]); } int kru() { int res = 0; sort(a,a+m); for (int i=1;i<=n;i++) p[i]=i; for (int i=0;i<m;i++) { int x=findfa(a[i].s); int y=findfa(a[i].e); if (x!=y) { p[x]=y; b[cnt++]=a[i]; res+=a[i].val; } } return res; } int kru1(node now) { int res=0; cnt=0; b[n-1]=now; sort(b,b+n); for (int i=1;i<=n;i++) p[i]=i; for (int i=0;i<n;i++) { int x=findfa(b[i].s); int y=findfa(b[i].e); if (x!=y) { p[x]=y; b[cnt++]=b[i]; res+=b[i].val; } } return res; } int main() { while (scanf("%d %d %d",&n,&m,&q)!=EOF) { for (int i=0;i<m;i++) scanf("%d %d %d",&a[i].s,&a[i].e,&a[i].val); cnt=0; kru(); while(q--) { node now; scanf("%d %d %d",&now.s,&now.e,&now.val); ans=kru1(now); printf("%d\n",ans); } } return 0; }
Total Submit: 347 Accepted: 118 Special Judge: No
A forest is full of sloths, they are so eager for tree leaves and as a result, very angry.
We assume that the forest is a map of N * M grids, and each of the gird is an empty land or contains a big sloth. It’s guaranteed that the sequence of the sloth is a continuous segment from the leftmost column for every row. ( You may consider that the number of columns M is infinite ).
As a sloth lover, you want to feed all the sloths as quick as possible. Every second you may select a rectangle area of the grids which only contains sloths and feed all the sloths there.
What’s the minimum time required to meet all the sloths’ needs in the forest?
The following line contains N numbers Ai, each describing the length of continuous sloths sequence from the left most column in every row. ( 1 <= Ai <= 10^9 )
3 4 5 5
The distributing situation of the sloths in the sample is as follow:
SSS
SSSS
SSSSS
SSSSS
And you can choose three rectangles to cover it.
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<queue> #include<vector> #include<ctype.h> #define LL __int64 using namespace std; const int MAXN=1000+5; const int INF=0x3f3f3f3f; int a[MAXN],id,n; bool judge(int a[]) { int Minn=INF; for(int i=0;i<n;i++) if(a[i]!=0 && a[i]<Minn) { Minn=a[i]; id=i; } if(Minn==INF) return false; else return true; } int main() { while(scanf("%d",&n)!=EOF) { int minn=INF; for(int i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]<minn) minn=a[i]; } int cnt=1; for(int i=0;i<n;i++) a[i]=a[i]-minn; while(judge(a)) { int minnum=a[id]; for(int i=id;i>=0;i--) { if(a[i]==0) break; a[i]=a[i]-minnum; } for(int i=id+1;i<n;i++) { if(a[i]==0) break; a[i]=a[i]-minnum; } cnt++; } printf("%d\n",cnt); } return 0; }
Total Submit: 225 Accepted: 41 Special Judge: No
The function f(x) is defined as the product of each numerical digit of the number x.
You are given a number n and required to calculate the number of x that satisfies f(x) = f(n) and doesn’t have number 1 as its numerical digit.
Next line contains a number n of length len..Each position corresponds to a number of 1-9.
No more than 10000 cases.
72
3
568
4
4123
176
17
Total Submit: 325 Accepted: 133 Special Judge: No
The number A is connected by n numerical digit a1a2a3a4……an.
You can separate it into two parts as a1a2a3..ak and ak+1ak+2…an and subtract the smaller one from the bigger one to get the number B.
Please find the minimum result of number B.
75462
734794666
387
68813
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<queue> #include<vector> #include<ctype.h> #define LL __int64 using namespace std; const int MAXN=30; char str[MAXN]; int work(char str[]) { int len=strlen(str); int num1=0,num2=0,ans1,ans2; if(len%2==1) { for(int i=0;i<=len/2;i++) num1=num1*10+(str[i]-'0'); for(int i=len/2+1;i<len;i++) num2=num2*10+(str[i]-'0'); ans1=abs(num1-num2); num1=0,num2=0; for(int i=0;i<len/2;i++) num1=num1*10+(str[i]-'0'); for(int i=len/2;i<len;i++) num2=num2*10+(str[i]-'0'); ans2=abs(num1-num2); return min(ans1,ans2); } else { for(int i=0;i<len/2;i++) num1=num1*10+(str[i]-'0'); for(int i=len/2;i<len;i++) num2=num2*10+(str[i]-'0'); return abs(num2-num1); } } int main() { while(scanf("%s",str)!=EOF) { int ans; ans=work(str); printf("%d\n",ans); } return 0; }
Total Submit: 243 Accepted: 128 Special Judge: No
Holding a contest is an interesting mission, and apparently arranging the problems is not exceptional, either.
You may consider that there are N problems prepared, and it's required to choose M problems to form the problem set of the upcoming contest.
What's more, the evaluating function of all the problems choosed is as follows:
Where Xi represents the hardness of the i_th problem and X represents the average of the M problems.
However, the contest principal Alice has lost himself in April disease, and just wants to hold the worst contest ever.(Sounds horrible...)
Now he wonders, what's the minimum value of s^2 can be.
The following line will contain N numbers Xi. ( 1 <= Xi <= 10^9 )
(Please keep three decimal places.)
6 10 1 2
5 2
1 8 3 4 9
0.250
#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<cmath> #include<queue> #include<algorithm> using namespace std; const int INF=0x3f3f3f3f; int a[35],n,m; int main() { while(scanf("%d%d",&n,&m)!=EOF) { double sum,ave,ans,cnt=INF,t=0; for(int i=0; i<n; i++) scanf("%d",&a[i]); sort(a,a+n); for(int j=0; j<n-1; j++) { sum=0;ans=0; for(int i=t; i-t<m; i++) sum+=a[i]; ave=sum/m; for(int i=t; i-t<m; i++) { ans+=(a[i]-ave)*(a[i]-ave); } ans/=m; if(cnt>ans)cnt=ans; t++; } printf("%.3lf\n",cnt); }return 0; }
Total Submit: 285 Accepted: 119 Special Judge: No
Alice, Fzz’s daughter is a primary school student. Fzz loves his daughter so much that he drives to school every day exactly on time when the school day is over, which means when Fzz arrives school the school day is exactly over.
It is the 100th anniversary celebration of school today. After some interesting activities, the principal announce that school is over. Alice watches her watch, and she knows it is x minutes earlier compared to the time when the school day usually ends. She starts to go home.
After y minutes, she meets her Dad. Then she gets on the car. They go home happily by car.
When she arrives home, she finds it is z minutes earlier compared to the usual.
Alice is good at math. She wants to challenge her dad with some questions.
Now she gives two numbers of x, y, z and asks his father to calculate the third one.
For example, she says “dad, when y equals 30, and z equals to 20, what’s the x?”
Fzz gives the answer ‘40’ right after the question.
However it’s your turn. Can you calculate it?
First line contains an integer n, the number of test cases (n<=10000).
For each case, there are 2 integers and 1 character ‘?’. The first stands for x, the second stands for y, and the third stand for z.
? 30 20
40 ? 20
40 30 ?
30
20
这道题我题目都没看,队友敲的
先贴代码= =
#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<cmath> #include<queue> #include<algorithm> //const int maxn; using namespace std; char s[1000]; int num[5]; int main(){ int n; int i,j,k; int que; scanf("%d",&n); while(n--) { int cnt=0; for(i=0;i<3;i++) { scanf("%s",s); if(s[0]!='?') { int temp=0; int wei=1; for(j=strlen(s)-1;j>=0;j--) { temp+=(s[j]-'0')*wei; wei*=10; } num[i]=temp; } else que=i; } if(que==0) { num[0]=(num[2]+2*num[1])/2; } if(que==1) { num[1]=(2*num[0]-num[2])/2; } if(que==2) { num[2]=2*num[0]-2*num[1]; } printf("%d\n",num[que]); } return 0; }
Total Submit: 179 Accepted: 20 Special Judge: No
As Cyy and Fzz are both busy repairing the network, Sama feel a little boring because it’s he who select Teemo during that game. Of cause his Teemo will stay alive since he has used the summoner spell Flash to avoid being killed. Since there is no network available, he wants to do something else to pass the time. He writes some strings randomly on the paper to kill the boring time.
A few minutes later he realizes that what he writes on the paper is not truly random, in fact it reflects what he is concerned about. Then he comes up with a question, what is the expect number of interesting strings that will appear in the random string he writes? (The characters Sama writes are all lowercase Latin letters, in this problem we consider the probability that each character appears as the same, that is, 1/26)
Then followed by T test cases. The first line of each test case contains two integers n and L(n <= 8, L <= 14), the number of interesting strings and the length of the string that Sama writes, then followed by n lines, the interesting strings. We promise that the interesting string is not longer than 12. (Notice that there may exist two or more same strings among the n interesting strings.)
1 1
a
3 4
cyy
fzz
sama
8 14
fatezero
nisekoi
nogamenolife
monthlygirls
nozakikun
datealive
sakura
sora
0.000230
0.000024