- 博客(32)
- 收藏
- 关注
原创 7-10 月饼 (25 分)
#include<stdio.h>#include<cstdlib>#include<iostream>#include<bits/stdc++.h>#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);using namespace std;struct str{ double b,a; double c;} s[10010];bool cmp(str a,s
2021-09-08 19:33:59
228
原创 7-56 小H分糖果 (20 分)
#include<bits/stdc++.h>#define ll long long#define INF 0x7f7f7f7f //2139062143#define llINF 9223372036854775807#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;int n;int num[100007],cas[100007];int main(){
2021-09-08 19:33:26
1350
原创 7-10 月饼 (25 分)
```cpp#include<stdio.h>#include<cstdlib>#include<iostream>#include<bits/stdc++.h>#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);using namespace std;struct str{ double b,a; double c;} s[10010];bool cmp.
2021-09-08 19:32:06
171
原创 7-55 字母表 (20 分)
#include<bits/stdc++.h>#define ll long long#define INF 0x7f7f7f7f //2139062143#define llINF 9223372036854775807#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;int main(){ IOS int t;cin>>t; wh
2021-09-08 19:31:31
363
原创 7-54 矩阵链相乘问题 (20 分)
#include <bits/stdc++.h>using namespace std;const int MAX = 1005;int p[MAX];int m[MAX][MAX];int n;void matrix(){ int i,j,r,k; memset(m,0,sizeof(m)); for(r = 2; r<=n; r++) { for(i = 1; i<=n-r+1; i++) {
2021-09-07 19:43:55
254
原创 7-8 (选做) 第k小 (10 分)
#include<bits/stdc++.h>#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;int main(){ IOS int n, k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) { cin>>a[i]; }
2021-09-07 19:43:24
322
原创 7-17 修理牧场 (25 分)
#include <iostream>#include <vector>#include <queue>using namespace std;int main(){ priority_queue<int, vector<int>, greater<int> > a; int n, temp; cin >> n; int i; for (i = 0; i < n; i++) { cin
2021-09-07 19:42:51
88
原创 7-35 公路村村通 (30 分)
#include<stdio.h>#include<string.h>int G[10000][10000];int main(void) { int n,m,a,b,c,s=0,p,i,t=0,j,min,flag=0,cost[10000],k,sum=0; scanf ("%d %d",&n,&m); if (m<n-1){ printf ("-1"); return 0; } for (i=1;i<=n;i++) {
2021-09-07 19:42:02
182
原创 7-4 输油管道问题 (50 分)
#include<bits/stdc++.h>#define ll long long#define INF 0x7f7f7f7f //2139062143#define llINF 9223372036854775807#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;int main(){ IOS int n;cin>>n; in
2021-09-07 19:41:23
458
原创 7-3 PAT排名汇总 (25 分)
#include<iostream>#include<algorithm>#include<string>#include<vector>using namespace std;struct PNode{ string kh; int grade; int zzpm; int kdpm; int kdcode;};bool comb(PNode a, PNode b){ if (a.grade != b.grade) retu
2021-09-07 19:40:46
1314
原创 7-2 银行业务队列简单模拟 (25 分)
#include<stdio.h>int main(){ int a[1001],b[1001],c[1001]; int n,x=0,y=0,i=0,m,k,j=0,index=0; scanf("%d",&n); for(k=0;k<n;k++) { scanf("%d",&m); if(m%2!=0) b[j++]=m; else c[i++]=m; } while(x<j||y<i)//j是奇数,i是偶数,j是VI
2021-09-07 19:40:10
458
原创 6-25 0/1背包问题 (队列式分枝限界法) (40 分)
void bound(NodeType &e) //算分枝结点e的上界{ int i=e.i+1; int sumw=e.w; double sumv=e.v; while((sumw+w[i]<=W)&&i<=n) { sumw+=w[i]; sumv+=v[i]; i++; } if(i<=n) e.ub=sumv+(W-sumw)*v[i]/w[i];
2021-09-07 19:39:41
841
原创 6-4 单链表逆转 (20 分)
List Reverse( List L )//前插法{ struct Node *p,*L1=(struct Node*)malloc(sizeof(struct Node)); L1->Next=NULL; struct Node *p1=L; while(p1!=NULL)//前插法,返回的是一个新链表,记住这点 { p=(struct Node*)malloc(sizeof(struct Node)); p->Da
2021-09-07 19:39:02
306
原创 6-3 带头结点的链式表操作集 (20 分)
List MakeEmpty(){ List L; L=(PtrToLNode)malloc(sizeof(struct LNode)); L->Next=NULL; return L;}Position Find( List L, ElementType X ){ PtrToLNode p=L->Next; while(p){ if(p->Data==X){ return p; } p=p->Next; } return ERROR;}b
2021-09-07 19:37:19
273
原创 7-54 矩阵链相乘问题 (20分)
#include <bits/stdc++.h>using namespace std;const int MAX = 1005;int p[MAX];int m[MAX][MAX];int n;void matrix(){ int i,j,r,k; memset(m,0,sizeof(m)); for(r = 2; r<=n; r++) { for(i = 1; i<=n-r+1; i++) {
2021-01-07 12:38:45
554
原创 7-31 图着色问题 (25分)
#include <iostream>#include <cstdio>#include <math.h>#include <string.h>#include <string>#include <algorithm>#include <stack>#include <list>#include <vector>#include <set>using namespace
2021-01-07 12:37:18
261
原创 6-5 两个有序链表序列的合并 (15分)
List Merge( List L1, List L2 ){ List p1,p2; List pm;struct Node *p=(struct Node*)malloc(sizeof(struct Node));p1=L1->Next;p2=L2->Next;//注意题目中是有头结点的所以要用p1=L1->Next;而不是p1=L1; pm=p;while(p1!=NULL&&p2!=NULL)//注意题目中说了利用原来的节点所以不用每次都开
2021-01-07 12:37:08
901
原创 7-34 旅游规划 (25分)
#include <iostream> using namespace std; int g[502][502][2]; // 邻接表.[0]:距离,[1]:花费 const int inf = 0x3f3f3f3f; int main() { std::ios::sync_with_stdio(false); // 不加此语句,会有超时 int n, m, s, d; int dis, charge; int u, v; ci
2021-01-07 12:36:53
283
原创 6-13 Quick Power (4分)
int Power(int N, int k){ int n = 1; N = N % MOD; while (k > 0) { if (k % 2 == 1) n = n * N % MOD; k /= 2; N = N * N % MOD; } return n;}
2021-01-07 12:11:55
404
原创 6-1 二分查找 (20分)
Position BinarySearch(List L, ElementType X) { int low = 1, high = L->Last; //置区间初值 while (low <= high) { //确保待查区间有意义 int mid = (low + high) / 2; if (L->Data[mid] == X) //找到待查元素X return mid; else i
2021-01-07 12:11:48
175
原创 7-29 0-1背包 (20分)
#include<iostream>#include<algorithm> using namespace std;const int maxn=110;const int maxv=1010; int n,V;int dp[maxv]={0},w[maxn],c[maxn]; int main(){ cin>>n>>V; for(int i=1;i<=n;i++) cin>>w[i]>>
2021-01-07 12:11:41
206
原创 7-15 古老的汉诺塔 (20分)
#include<bits/stdc++.h>#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);using namespace std;int n,cou=0;void hanio(int n,char a,char b,char c) //b为中间 { cou++; if(n==1) { cout<<a<<"-->"<<c<<endl; } else
2021-01-07 12:11:33
762
原创 7-17 修理牧场 (25分)
#include <iostream>#include <vector>#include <queue>using namespace std;int main(){ priority_queue<int, vector<int>, greater<int> > a; int n, temp; cin >> n; int i; for (i = 0; i < n; i++) { cin
2021-01-07 12:11:25
367
原创 7-8 装箱问题 (20分)
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int a[1005];int main(){int n,x;cin>>n;for(int i=1;i<=n;i++)a[i]=100;for(int j=0;j<n;j++){ cin>>x; for(int i=1;;i++){ if(x<=a[i]){
2021-01-07 12:11:18
295
原创 7-31 图着色问题 (25分)
#include<bits/stdc++.h>#define ll long long#define INF 0x7f7f7f7f //2139062143#define llINF 9223372036854775807#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;int v,e,k;int x[1000007],y[1000007];int main()
2021-01-07 12:11:12
255
原创 7-7 铺设油井管道 (30分)
#include<bits/stdc++.h>#define ll long long#define INF 0x7f7f7f7f //2139062143#define llINF 9223372036854775807#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;int x[1000000],y[1000000];int main(){ IOS
2021-01-07 12:11:05
1890
原创 7-6 第k小元素 (20分)
#include<bits/stdc++.h>#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;int main(){ IOS int n, k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) { cin>>a[i]; }
2021-01-07 12:10:59
215
原创 7-33 冒泡法排序 (20分)
#include <stdio.h>int main(){ int N,M; scanf("%d%d",&N,&M); int ar[N]; for(int i=0;i<N;i++){ scanf("%d",&ar[i]); } for(int i=0;i<M;i++){ for(int j=0;j<N-i-1;j++){ if(ar[j]>
2021-01-07 12:10:53
128
原创 7-10 月饼 (25分)
#include<stdio.h>#include<cstdlib>#include<iostream>#include<bits/stdc++.h> using namespace std;struct str{ double b,a; double c;} s[10010];bool cmp(str a,str b){ return a.c>b.c;}int main(){ int n,m;
2021-01-07 12:10:46
140
原创 7-8 装箱问题 (20分)
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int a[1005];int main(){int n,x;cin>>n;for(int i=1;i<=n;i++)a[i]=100;for(int j=0;j<n;j++){ cin>>x; for(int i=1;;i++){ if(x<=a[i]){
2021-01-07 12:10:40
441
原创 7-2 银行业务队列简单模拟 (25分)
#include<stdio.h>int main(){ int a[1001],b[1001],c[1001]; int n,x=0,y=0,i=0,m,k,j=0,index=0; scanf("%d",&n); for(k=0;k<n;k++) { scanf("%d",&m); if(m%2!=0) b[j++]=m; else c[i++]=m; } while(x<j||y<i)//j是奇数,i是偶数,j是VI
2021-01-07 12:10:33
1160
原创 7-1 堆栈操作合法性 (20分)
#include#include#include#include<stdlib.h>using namespace std;int main(){int N,M;cin>>N>>M;char stack[100];for(int i=0;i<N;i++){scanf("%s", stack);int l = 0, len = strlen(stack), flag = 1;for(int j=0; j<len; j++){if(
2021-01-07 12:10:19
776
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人