- 问答
111
- 2025-7-13 20:06:35 @
答案专用
14 条评论
-
-
#include <bits/stdc++.h> using namespace std; struct node{ int data; node *next; }; int main(){ int n; cin>>n; node *head=new node; head->data=1; head->next=NULL; node *p=head; for(int i=2;i<=n;i++){ node *s=new node; s->data=i; s->next=NULL; p->next=s; p=s; } p=head; while(p!=NULL){ cout<data<<" "; p=p->next; } return 0; }
-
#include using namespace std; struct node{ int data; node *next; }; int main(){ int n; cin>>n; node *head=new node; head->data=1; head->next=NULL; node *p=head; for(int i=2;i<=n;i++){ node *s=new node; s->data=i; s->next=NULL; p->next=s; p=s;
} p=head; while(p!=NULL){ cout<data<<" "; p=p->next; } return 0; } -
/陈璞瑜 #include<bits/stdc++.h> using namespace std; struct goods{ int sum,num,ave; }; bool cmp(goods x,goods y){ return x.ave>y.ave; } int main(){ goods a[101]; int n,l; cin>>n>>l; for(int i=1;i<=n;i++){ cin>>a[i].sum>>a[i].num; a[i].ave=a[i].sum/a[i].num; } sort(a+1,a+n+1,cmp); int p=0; for(int i=1;i<=n;i++){ if(a[i].num<=l){ p=p+a[i].sum; l=l-a[i].num; }else{ p=p+a[i].ave*l; break; } } cout<<p; return 0; }
-
#include using namespace std; struct goods{ int sum,num,ave; }; bool cmp(goods x,goods y){ return x.ave>y.ave; }; int main(){ goods a[101]; int n,l,p=0; cin>>n>>l; for(int i=1;i<=n;i++){ cin>>a[i].sum>>a[i].num; a[i].ave=a[i].sum/a[i].num; } sort(a+1,a+n+1,cmp); for(int i=1;i<l;i++){ if(a[i].num<=1){ p*=a[i].sum; l-=a[i].num; } else{ p+=a[i].ave*l; } } cout<<p; return 0; }
- 1