diff --git a/a.txt b/a.txt new file mode 100644 index 0000000..60bda9a --- /dev/null +++ b/a.txt @@ -0,0 +1,543 @@ +实验1.1半数集问题 +#include +using namespace std; +int a[1005]={0}; //存放已计算的数据 +int b[1005]={0}; +int halfset(int n){ +int sum = 1; + if(a[n]>0) //如果f(n)已经得出,就不必再重复计算 + return a[n]; + for(int i=1;i<=n/2;i++){ + sum += halfset(i); + } + a[n]=sum; + return sum; +} +int main() +{ + int n = 0,i = 0; + cin>>n; + while(n!=0){ + b[i++] = n; + cin>>n; + } + for(int j=0;j +#include +#include +void mov(int n,char a,char b) +{ + printf("%d %c %c\n",n,a,b); +} +void dg(int n,char a, char c, char b) +{ + if(n==1) mov(n,a,b); + else + { + dg(n-1,a,b,c); + mov(n,a,b); + dg(n-1,c,a,b); + } +} +int main() +{ + char a='A',b='B',c='C'; + int n; + while(scanf("%d",&n)!=EOF) + dg(n,a,c,b); + return 0; +} +实验1.3 整数因子分解问题 +#include +using namespace std; +mapa; +int f(int n){ + if(n == 1) + return 1; + if(a[n]) + return a[n]; + int count=1; + for(int i=2;i<=sqrt(n);i++){ + if(n%i == 0){ + count+=f(i); + if(i!=n/i){ + count+=f(n/i); + } + } + } + a[n] = count; + return a[n]; +} +int main() +{ + int n; + while(cin>>n){ + cout< +#include +using namespace std; +int a[200][200]; +int cost[200]; +int city,result; +int travel(){ + cost[city-2] = a[city-2][city-1]; + for(int i = city-3;i>=0;i--){ + result = a[i][city-1]; + for(int j = i+1;j>city; + for(int i = 0;i>a[i][j]; + } + } + result = travel(); + cout< +using namespace std; +const int N = 1e3 + 10; +#define Ma_x 99999 +#define Mi_x 0 +#define min(a,b) ab?a:b +int n,w[N],dp[N][N],dq[N][N]; +int sum(int i,int t){ + int k,s=0,k1; + for(k=i;k +#include +using namespace std; +string a,b; +int k; +int value[10000][10000]; +int main(){ + cin>>a>>b>>k; + int alen=a.size(); + int blen=b.size(); + for(int i=0;i<=alen;i++){ + value[i][0]=k*i; + } + for(int i=1;i<=blen;i++){ + value[0][i]=k*i; + } + for(int i=1;i<=alen;i++){ + for(int j=1;j<=blen;j++){ + value[i][j]=min(min(value[i-1][j]+k,value[i][j-1]+k),value[i-1][j-1]+abs(a[i-1]-b[j-1])); + } + } + cout< +#include +using namespace std; +int n; +int m[15][15]; +int f[25][15][15]; +int main() { + cin >> n; + int x, y, z; + while (cin >> x >> y >> z) { + if (!x && !y && !z) break; + m[x][y] = z; + } + for (int k = 2; k <= 2 * n; k ++ ) + for (int i = 1; i <= n; i ++ ) + for (int j = 1; j <= n; j ++ ) { + int a = k - i, b = k - j; + if (a >= 1 && a <= n && b >= 1 && b <= n) { + int t = max(max(f[k - 1][i - 1][j], f[k - 1][i][j]), max(f[k - 1][i][j - 1], f[k - 1][i - 1][j - 1])); + if (i == j) f[k][i][j] = t + m[i][a]; + else f[k][i][j] = t + m[i][a] + m[j][b]; + } + } + cout << f[2 * n][n][n]; + return 0; +} +实验2.5双胞胎做题 +#include +using namespace std; +int f[1000][1000]; +int a[10000],b[10000]; +int n,sum,result=9999; + +void resulta(){ + memset(f, 0, sizeof(f)); + for(int i=1;i<=n;i++){ + + for(int j=0;j<=sum;j++){ + if(jt) + result=t; + } +} + +int main(){ + cin>>n; + for(int i=1;i<=n;i++){ + cin>>a[i]; + sum=sum+a[i]; + } + for(int i=1;i<=n;i++){ + cin>>b[i]; + } + resulta(); + cout< + +using namespace std; +typedef long long ll; +ll dp[100002],n,m,s[100002]={0}; +mapT; +struct node{ + ll u;ll t; +}a[100002]; +int main() +{ + cin>>n>>m; + for(int i=0;i=1;i--){ + if(s[i]==0){dp[i]=dp[i+1];} + else{ + for(int j=0;j +#include +#include + +using namespace std; +struct huichang +{ + int s; + int f; +}; +huichang t[10000+10]; +int n; +bool cmp(huichang a, huichang b) { + return a.s < b.s; +} +int meeting() { + int count_chang = 0; + int *a = new int[n + 1]; //该数组于保存每个会场的结束时间 + for (int i = 0; i < n+1; i++) { + a[i] = 0; + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (a[j] <= t[i].s) { + a[j] = t[i].f; + if (j >= count_chang + 1) count_chang++; + break; + } + } + } + delete[]a; + return count_chang; +} +int main() { +cin >> n; +for (int i = 1; i <= n; i++) { +cin >> t[i].s >> t[i].f; +} +sort(t+1,t+n+1,cmp); +cout << meeting() << endl; +return 0; +} +实验3.2磁带最优存储问题 +#include +#include +#include +#include +using namespace std; +struct Tape +{ +int len; //长度 +int pr; //概率 +double tr; +friend bool operator< (Tape a,Tape b) {return a.tr>b.tr;} +Tape(int l=0,int p=0):len(l),pr(p),tr(l*p){}; +}; +priority_queuetape; +double minTimeCost(int n,priority_queue&tape,long long sum){ + double res=0,acc=0; + while(!tape.empty()) + { + acc+=tape.top().tr/sum;//计算tr累加值 + res+=acc; + tape.pop(); + } + return res; +} +int main() +{ + int n,a,b; + long long sum=0; + cin>>n; + for(int i = 0;i>a>>b; + tape.push(Tape(a,b)); + sum+=b;//计算概率和 + } + double res=minTimeCost(n,tape,sum); + cout< +using namespace std; +typedef long long ll; +typedef pair PII; +const int N = 1e5 + 10; +ll n; +ll dp[110][110]; +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + cin >> n; + memset(dp, 0, sizeof dp); + dp[1][1] = 1;// i个人分j个宿舍 + for (int i = 0; i <= n; i++) { + dp[i][0] = 0; + dp[i][1] = 1; + dp[0][i] = 0; + } + ll sum = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= i; j++) { + if(dp[i][j]==0) dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] * j; + } + } + for (int i = 1; i <= n; i++) { + sum += dp[n][i]; + } + cout << sum; + return 0; //17 +} +作业2.2烟台基地宿舍分配2 +#define _CRT_SECURE_NO_WARNINGS 1 +#include +using namespace std; +typedef long long ll; +typedef pair PII; +const int N = 1e5 + 10; +ll n,m; +ll dp[110][110]; +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + cin >> n>>m; + memset(dp, 0, sizeof dp); + dp[1][1] = 1;// i个人分j个宿舍 + for (int i = 0; i <= n; i++) { + dp[i][0] = 0; + dp[i][1] = 1; + dp[0][i] = 0; + } + ll sum = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= i; j++) { + if(dp[i][j]==0) dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] * j; + } + } + cout << dp[n][m]; + return 0; +} +作业3.1金字塔寻宝 +#include +#include +using namespace std; +const int N=105; +int n,*num,*lastNum,ary1[N],ary2[N]; +void dp() +{ +num=ary1,lastNum=ary2; +for(int i=1;i<=n;i++){ +for(int j=1;j<=i;j++){ +cin>>num[j]; +num[j]=max(lastNum[j],lastNum[j-1])+num[j]; +} +swap(num,lastNum); +} +} +int maxValue() +{ + int max=lastNum[1]; + for(int i=2;i<=n;i++) + if(lastNum[i]>max) max=lastNum[i]; + return max; +} + +int main() +{ + cin>>n;dp(); + cout< +using namespace std; +void getnumber(string s); +void getresult(); +const int N=1010; +int f[N][N],num[N][N],a[N]; +int d[N][N]; +int ans[N]; +int cnt; +int n,k; +int main(){ +string s; +int c,e; +cin>>n>>k; +cin>>s; +k--; +getnumber(s); +getresult(); +cout< +using namespace std; +const int N=10000; +int servicetime[N]; +int line[N]; +int main(){ + int n,s,sum,num; + cin>>n>>s; +for(int i=0;i>servicetime[i]; +} +sort(servicetime,servicetime+n); +sum=servicetime[0]+s; +num=1; +for(int i=0;i +using namespace std; +const int N=10000; +int servicetime[N]; +int line[N]; +int main(){ + int n,s,sum; + cin>>n>>s; + for(int i=0;i>servicetime[i]; + } + sort(servicetime,servicetime+n); + for(int i=0;i