Null.
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?
#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?
#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.
#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; }
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); } }