求和问题(二维向量)

本文探讨了二维向量的加法运算,详细解释了如何通过坐标相加实现两个二维向量的求和,同时阐述了其在几何和代数上的意义。无论是对于初学者还是深入研究向量的读者,都能从中理解二维向量求和的基本概念和应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<bits/stdc++.h>
#define UP(i,x,y) for(int i=x; i<=y; i++)
#define LEN 100001
using namespace std;
struct node{
    long long number;
    long long color;
    long long id; // 编号 
}; 
vector<node> arr;
vector< vector<node> >  arr2(LEN); // 二维向量
int n,m;

long long calScore(node a, node b)
{
    return (a.id + b.id) * (a.number + b.number);
}

int main()
{
    long long ans = 0;
//    cin>>n>>m;
    scanf("%d %d", &n, &m);
    UP(i, 1, n)
    {
        node temp;
//        cin>>temp.number;
        scanf("%lld", &temp.number);
        temp.id = i; 
        temp.color = 0;
        arr.push_back(temp);
    }
    UP(i, 1, n)
    {
        long long color;
//        cin>>color;
        scanf("%lld", &color);
        arr2[color].push_back(arr[i-1]);
    }
    
    for(vector< vector<node> >::iterator iter = arr2.begin(); iter != arr2.end(); iter++)
    {
        vector<node> vec_tmp = *iter; // 该向量中,颜色相同 
        if(vec_tmp.size() <= 0)
        {
        	continue;
        }
        vector<node>  vec_0; // id为奇数向量 
    	vector<node>  vec_1; // id为偶数向量
		
		/* node序列分成id为偶数的和id为奇数的 */ 
    	UP(i, 0, vec_tmp.size()-1)
    	{
    		if( vec_tmp[i].id % 2 == 0 )
    		{
    			vec_0.push_back(vec_tmp[i]);
			}
			else
			{
				vec_1.push_back(vec_tmp[i]);
			}
		}
    	
    	/* 求出偶数中分数之和 */
    	if(vec_0.size() > 0)
    	{
    		UP(i, 0, vec_0.size() - 1)
			{
				UP(j, i+1, vec_0.size() - 1)
				{
					ans = ((ans%10007) + calScore(vec_0[i], vec_0[j]) % 10007) ;
				}
			} 
		}
//    	cout<<ans<<endl; 
    	
    	
    	/* 求出奇数中分数之和 */
		if(vec_1.size() > 0)
		{
			UP(i, 0, vec_1.size() - 1)
			{
				UP(j, i+1, vec_1.size() - 1)
				{
					ans = ((ans%10007) + calScore(vec_1[i], vec_1[j]) % 10007);
				}
			} 
		}
    }
    cout<<ans % 10007;
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值