2 条题解

  • 2
    @ 2024-12-6 18:27:49

    除法题模板,只供参考

    #include <bits/stdc++.h>
    using namespace std;
    bool cmd(string a,string b){
    	if(a.size() > b.size()) return true;
    	else if(a.size() < b.size()) return false;
    	for(int i = 0 ; i < a.size() ; i++){
    		if(a[i] > b[i]) return true;
    		else if(a[i] < b[i]) return false;
    	}
    	return true;
    }
    int len,x[114514],y[114514],z[114514],t;
    bool ll = false;
    string a,b,c,d,e = "";
    int main(){
    	cin >> a >> b;
    	if(cmd(b,a)){
    		cout << 0 << endl << a << endl;
    		return 0;
    	}
    	for(int i = 1,j = 0 ; j < a.size() ; ){
    		t = 0; 
    		d = e + a.substr(j,i);
    		if(1){
    			for(int k = 9 ; k >= 0 ; k--){
    				memset(x,0,sizeof(x));
    				memset(y,0,sizeof(y));
    				memset(z,0,sizeof(z));
    				c = "";
    				for(int l = 0 ; l < b.size() ; l++) x[l] = b[b.size()-l-1] - '0';
    				for(int l = 0 ; l < b.size() ; l++){
    					z[l] += x[l] * k;
    					z[l+1] += z[l] / 10;
    					z[l] %= 10;
    				}
    				len = b.size() + 1;
    				while(!z[len] && len > 0) len--;
    				for(int l = 0 ; l <= len ; l++) c = char(z[l]+'0') + c;
    				if(cmd(d,c)){
    					if(k) ll = true;
    					if(ll) cout << k;
    					break;
    				}
    			}
    			memset(x,0,sizeof(x));
    			memset(y,0,sizeof(y));
    			memset(z,0,sizeof(z));
    			for(int k = d.size() - 1,l = 0 ; k >= 0 ; k--,l++) x[l] = d[k] - '0';
    			for(int k = c.size() - 1,l = 0 ; k >= 0 ; k--,l++) y[l] = c[k] - '0';
    			for(int k = 0 ; k < d.size() ; k++) x[k] -= y[k];
    			for(int k = 0 ; k < d.size() ; k++){
    				if(x[k] < 0){
    					x[k+1]--;
    					x[k] += 10;
    				}
    			}
    			e = "";
    			for(int k = d.size() - 1 ; k >= 0 ; k--){
    				if(x[k] != 0) t = 1;
    				if(t == 1) e = e + char(x[k]+'0');
    			}
    			if(t == 0) e = "";
    			j += i;
    			i = 1;
    		}
    	}
    	if(e == "") e = "0";
    	cout << endl << e << endl;
    	return 0;
    }
    
    • @ 2024-12-20 18:44:16
      #include <bits/stdc++.h>
      using namespace std;
      bool cmd(string a,string b){
      	if(a.size() > b.size()) return true;
      	else if(a.size() < b.size()) return false;
      	for(int i = 0 ; i < a.size() ; i++){
      		if(a[i] > b[i]) return true;
      		else if(a[i] < b[i]) return false;
      	}
      	return true;
      }
      int len,x[114514],y[114514],z[114514],t;
      bool ll = false;
      string a,b,c,d,e = "";
      int main(){
      	cin >> a >> b;
      	for(int i = 1,j = 0 ; j < a.size() ; ){
      		t = 0;
      		d = e + a.substr(j,i);
      		if(cmd(d,b)){
      			for(int k = 9 ; k >= 0 ; k--){
      				memset(x,0,sizeof(x));
      				memset(y,0,sizeof(y));
      				memset(z,0,sizeof(z));
      				c = "";
      				for(int l = 0 ; l < b.size() ; l++) x[l] = b[b.size()-l-1] - '0';
      				for(int l = 0 ; l < b.size() ; l++){
      					z[l] += x[l] * k;
      					z[l+1] += z[l] / 10;
      					z[l] %= 10;
      				}
      				len = b.size() + 1;
      				while(!z[len] && len > 0) len--;
      				for(int l = 0 ; l <= len ; l++) c = char(z[l]+'0') + c;
      				if(cmd(d,c)){
      					cout << k;
      					ll = true;
      					break;
      				}
      			}
      			memset(x,0,sizeof(x));
      			memset(y,0,sizeof(y));
      			memset(z,0,sizeof(z));
      			for(int k = d.size() - 1,l = 0 ; k >= 0 ; k--,l++) x[l] = d[k] - '0';
      			for(int k = c.size() - 1,l = 0 ; k >= 0 ; k--,l++) y[l] = c[k] - '0';
      			for(int k = 0 ; k < d.size() ; k++) x[k] -= y[k];
      			for(int k = 0 ; k < d.size() ; k++){
      				if(x[k] < 0){
      					x[k+1]--;
      					x[k] += 10;
      				}
      			}
      			e = "";
      			for(int k = d.size() - 1 ; k >= 0 ; k--){
      				if(x[k] != 0) t = 1;
      				if(t == 1) e = e + char(x[k]+'0');
      			}
      			if(t == 0) e = "";
      			j += i;
      			i = 1;
      		}
      		else{
      			i++;
      			if(ll) cout << "0";
      		}
      	}
      	if(e == "") e = "0";
      	cout << endl << e << endl;
      	return 0;
      }
      
  • -5
    @ 2024-5-26 16:34:47

    sdfghjk

    • 1

    信息

    ID
    1188
    时间
    1000ms
    内存
    128MiB
    难度
    9
    标签
    递交数
    149
    已通过
    13
    上传者