第五届华中区程序设计邀请赛暨武汉大学第十四届校赛 网络预选赛
Null.
#include <iostream> #include <string.h> using namespace std; int main() { string s; cin>>s; cout<<s<<endl; return 0; }
There are N+1 rows and M+1 columns fence with N*M grids on the grassland. Each grid has a sheep. In order to let the sheep together, we need to dismantle the fence. Every time you can remove a row or a column of fences. What’s the least number of times to reach the goal?
The first line of each case contains two integers N and M. (1≤N,M≤1000)
2 2
2
#include <iostream> #include <string.h> #include <stdio.h> using namespace std; int min(int a,int b) { if(a<b) return a; else return b; } int main() { int a,b; while(scanf("%d%d",&a,&b)!=EOF) { int ans=min(a,b); if(a==1&&b==1) ans = 0; printf("%d\n",ans); } return 0; }
There are N apples. Two people take turns to either:
1. Divide the apple into two piles with different numbers.
2. The other people selects a pile of apples as the beginning of the next turn.
If someone can not meet the requirements, he is lost. Will the first one win the game if both use the best strategy?
The first line of each case contains a integer N. ( 1 <= N <= 1000000000 )
3
4
Yes
No
#include <iostream> #include<string.h> #include<string> #include<stdio.h> #include<algorithm> using namespace std; typedef long long LL; const int MOD=1000000007; int main(){ int N; while(scanf("%d",&N)!=EOF){ if(N==1||N==2||N==4) { printf("No\n"); continue; } if(N==3) { printf("Yes\n"); continue; } if(N%3==1) { printf("No\n"); } else { printf("Yes\n"); } } return 0; }
There are n numbers A[1] , A[2] .... A[n], you can select m numbers of it A[B[1]] , A[B[2]] ... A[B[m]] ( 1 <= B[1] < B[2] .... B[m] <= n ) such that Sum as small as possible.
Sum is sum of abs( A[B[i]]-A[B[j]] ) when 1 <= i < j <= m.
First line of each case contains two integers n and m.( 1 <= m <= n <= 100000 )
Next line contains n integers A[1] , A[2] .... A[n].( 0 <= A[i] <= 100000 )
It's guaranteed that the sum of n is not larger than 1000000.
5 1 7 10
5 3
1 8 6 3 10
8
#include<iostream> #include<stdio.h> #include<algorithm> using namespace std; const int maxn=100000+10; typedef long long ll; ll a[maxn]; ll he; int cmp(ll a,ll b) { return a>b; } int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) { he=0; for(int i=1; i<=n; i++) { scanf("%lld",&a[i]); } sort(a+1,a+n+1,cmp); ll s=0; for(int i=1; i<=m; i++) { s+=(m-i)*a[i]; he+=a[i]; } for(int i=1; i<=m; i++) { s-=(i-1)*a[i]; } ll ans=s; for(int i=m+1; i<=n; i++) { // ll k=s-(m-1)*a[i-m]+2*(he-a[i-m])-(m-1)*a[i]; ll k=s-(m-1)*a[i]+2*(he-a[i-m])-(m-1)*a[i-m]; ans=min(ans,k); s=k; he=he-a[i-m]+a[i]; } printf("%lld\n",ans); } return 0; }
Each test case consists of 5 integers L, A, B, D, Dir in a line. The meanings of L, A, B, D are as described above. Dir means whether they are in the same direction. Dir = 1 means they are in the same direction, while Dir = 0 means they are in the opposite direction. ( 1 <= L, A, B, D <= 32768, 0 <= Dir <= 1 )
1200 200 400 300 1
0.500000
Please pay attention to the speed of I/O.
#include <iostream> #include<string.h> #include<string> #include<stdio.h> #include<algorithm> using namespace std; typedef long long LL; const int MOD=1000000007; int main() { int L,A,B,D,dir; double ans; while(scanf("%d%d%d%d%d",&L,&A,&B,&D,&dir)!=EOF) { if(dir == 1) { if(A == B) ans = 1; else { if(2*D/L>=1) ans = 1; else ans=2*D*1.0/L; } } else if(dir == 0) { if(2*D/L>=1) ans = 1; else { ans=2*D*1.0/L; } } printf("%.6lf\n",ans); } }