HOW CF B!
  • 板块学术版
  • 楼主02Ljh
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/3/29 19:08
  • 上次更新2023/10/23 20:06:30
查看原帖
HOW CF B!
578004
02Ljh楼主2023/3/29 19:08

qwq WA on #5

#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define int long long
#define ull unsigned long long
#define ll long long
#define MAXN 1
#define WA cout<<"CCF\n";
#define eps 1e-5
#define ls i*2
#define rs i*2+1
#define none -1145141919
#define pii pair<int,int>
#define Y cout<<"Yes\n"
#define N cout<<"No\n"
#define H cout<<"\n"
const int MOD=1e9+7;
vector< vector<int> > q;
int n,m;
 main()
{
    int _;
    cin>>_;
    while(_--)
    {
        q.clear();
        //cout<<3/2;
        cin>>n>>m;
        int tot=0;
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            q.push_back(vector<int>());
            for(int j=1;j<=m;j++)
            {
                int lxy;
                cin>>lxy;
                q[i-1].push_back(lxy);
            }
        }
        for(int i=0;i<m;i++)
        {
            vector<int> yu;
            yu.clear();
            //YUuuuu_
            for(int j=0;j<n;j++)
            {
                yu.push_back(q[j][i]);
                //cout<<q[j][i]<<" ";
            }
           // H;
            sort(yu.begin(),yu.end());
            if(n%2==1)
            {
                int fl=n/2,tim=n-1;
                for(int j=0;j<fl;j++)
                {
                    ans+=abs((tim)*yu[j]);
                    tim--;
                }
                tim++;
                for(int j=fl+1;j<n;j++)
                {
                    ans-=abs((tim)*yu[j]);
                    tim++;
                }
                ans=abs(ans);
            }

            else
            {
                int fl=n/2,tim=n-1;
                for(int j=0;j<fl;j++)
                {
                    ans+=abs((tim)*yu[j]);

                    //cout<<"ans="<<ans<<"\n";

                    tim-=2;
                }
                tim+=2;
                for(int j=fl;j<n;j++)
                {
                    ans-=abs((tim)*yu[j]);

                    //cout<<"ans="<<ans<<"\n";

                    tim+=2;
                }
                ans=abs(ans);
            }
            //cout<<ans<<"\n";
            tot+=ans;
            ans=0;
        }
        cout<<tot<<"\n";
    }
    return 0;
}
/*
a1 a2 a3
b1 b2 b3
c1 c2 c3

|a1-b1|
|a1-c1|
|b1-c1|
1 2 3
-1+-2+-1 =4
a+a-c-c

a1 b1 c1 d1
a+a+a+b-c-d-d-d

a b c d e
a+a+a+a+b+b-d-d-e-e-e-e

a b c d e f
a+a+a+a+a+b+b+b+c-d-e-e-e-f-f-f-f-f

n_num%2==1
*/
/*
1 1 3 4
11
*/

2023/3/29 19:08
加载中...