#include<cstdio> #include<cstring> #include<string> #include<math.h> #include<iostream> #include<algorithm> #include<iomanip> #include<vector> #include<map> #include<set> #include<stack> #include<cstdlib> #define eps 1e-9 const double pi = acos(-1.0); #define ll long long const ll N = 1e8; using namespace std; struct poly { int e; double c; }ans[10000],p[10000]; int main() { int n, e, c, m = -1, cnt = 0;//m记录a中最高次e的指数, map<int, double>q; cin >> n; for (int i = 0; i < n; i++) { cin >> e >> c; q[e] = c;//将多项式a的指数和系数值都存入map中 if (i == 0)m = e;//找到最高次指数 } cin >> n; for (int i = 0; i < n; i++)cin >> p[i].e >> p[i].c; while (m >= p[0].e)//若a中的最高次比b中最高次大 { double change = q[m] / p[0].c;//a的最高次除以b最高次的系数比 double diff = m - p[0].e;//指数比,减完之后的值 if (fabs(change) >= 0.05) { ans[cnt].e = diff;//将系数和指数都存入ans数组中 ans[cnt++].c = change; for (int i = 0; i < n; i++) { q[p[i].e + diff] -= change*p[i].c;//change乘以b更新a中的变化 } } else m--;//就执行判断下一项 while (fabs(q[m]) < 0.05&&m >= p[0].e)m--; } cout << cnt; if (!cnt)cout << " 0 0.0"; for (int i = 0; i < cnt; i++)printf(" %d %.1lf", ans[i].e, ans[i].c); cout << endl; cnt = 0; while (m >= 0) { if (fabs(q[m]) >= 0.05) { ans[cnt].e = m; ans[cnt++].c = q[m]; } m--; } cout << cnt; if (!cnt)cout << " 0 0.0"; for (int i = 0; i < cnt; i++)printf(" %d %.1lf", ans[i].e, ans[i].c); return 0; }
#include<iostream> #include<algorithm> #include<string.h>//memset()函数的头文件 using namespace std; typedef long long LL; LL acv[100100],sum[100100]; int main() { memset(acv,0,sizeof(acv)); memset(sum,0,sizeof(sum)); int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%lld",&acv[i]); } sort(acv+1,acv+1+n); sum[0]=0; for(int i=1;i<=n;i++){ sum[i] = sum[i-1]+acv[i];//一个累加过程 } int a1 = n/2;//前半部分 int b1 = n-n/2;//后半部分 LL diff1 = sum[n] - 2*sum[a1];//减去前半部分 LL diff2 = sum[n] - 2*sum[b1];//减去后半部分 if(diff1>diff2){//比较哪一部分大 printf("Outgoing #: %d\n",b1); printf("Introverted #: %d\n",a1); printf("Diff = %lld\n",diff1); } else { printf("Outgoing #: %d\n",a1); printf("Introverted #: %d\n",a1); printf("Diff = %lld\n",diff2); } }
标签:cnt,int,8.8,ans,printf,include,change From: https://www.cnblogs.com/xuxingkai/p/17615215.html