2019 年华东师范大学机试
没有经过数据的检验,如果有错误欢迎指正
找规律后可以找到这个。
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf = 0x3f3f3f3f; const double eps = 1e-6; const ll N = 1e5+7; int main(){ ll a,g,c,k; cin>>a>>g>>c>>k; if(k&1){ cout<<g-a<<endl; }else{ cout<<a-g<<endl; } return 0; }
固定任意一条边(我这里用了最大 然后二分角度)
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf = 0x3f3f3f3f; const double eps = 1e-9; const double pi = acos(-1.0); const ll N = 1e5+7; vector<int> v; double len(double x1,double y1,double x2,double y2){ double x=(x2-x1)*(x2-x1); double y=(y2-y1)*(y2-y1); return sqrt(x+y); } int sgn(double x){ if(fabs(x) < eps)return 0; if(x < 0)return -1; else return 1; } int main(){ int x; for(int i=0;i<3;i++){ cin>>x; v.push_back(x); } sort(v.begin(),v.end()); double l,r; l=0; r=pi/2; double ansx,ansy; //cout<<asin(3.0/5)<<endl; while(1){ double mid=(l+r)/2; double xx=v[1]*cos(mid); double yy=v[1]*sin(mid); //cout<<mid<<" "<<len(xx,yy,v[2],0)<<" "<<v[0]<<endl; if(sgn(len(xx,yy,v[2],0)-v[0])==0){ ansx=xx; ansy=yy; //cout<<ansx<<" "<<ansy<<endl; break; }else{ if(sgn(len(xx,yy,v[2],0)-v[0])==1){ r=mid; }else{ l=mid; } } } cout<<"0 0"<<endl; cout<<v[2]<<" 0"<<endl; //cout<<ansx<<endl; printf("%.1f %.1f\n",ansx,ansy); //cout<<ansx<<" "<<ansy<<endl; return 0; }
模拟即可
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf = 0x3f3f3f3f; const double eps = 1e-6; const ll N = 1e5+7; int ans[107]; int main(){ int k; string s; cin>>k>>s; for(int i=0;i<s.length();i++){ ans[i%k]+=s[i]-'0'; } int c=0; // for(int i=0;i<k;i++){ // cout<<ans[i]; // } while(1){ for(int i=k-1;i>=0;i--){ int tmp=(ans[i]+c)%2; c=(ans[i]+c)/2; ans[i]=tmp; } if(c==0) break; } for(int i=0;i<k;i++){ cout<<(!ans[i]); } cout<<endl; return 0; } //4 //101101100111 //0110 //16 //1111111111111111 //0000000000000000 //16 //10100000110000111110100101001000 //0111010111110011
待做