个人赛-8

C题-planet communication

用坐标判断向量平行:

if (x * y1 == x1 * y && x * z1 == x1 * z && y * z1 == y1 * z)

不要用对应坐标成比例,还需要特判比例为0.
思路就是假设每一个星球都需要一个光线,那么每有一个星球与某个星球处于同一直线上,就减去需要发射的光线数,因为光线是双向的且无限距离,所以只需要用平行来判定是否两星球是否共线。

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define ll long long
using namespace std;
const int N = 5010;
int n;
ll a[N], b[N], c[N];
ll x0, y0, z0, x, y, z, x1, y1, z1;
bool vis[N];
int main() 
{
    cin >> n;
    cin >> x0 >> y0 >> z0;
    for (int i = 1; i < n; i++) 
    {
        cin >> x >> y >> z;
        a[i] = x - x0;
        b[i] = y - y0;
        c[i] = z - z0;
    }
    int ans = n - 1;
    for (int i = 1; i < n; i++) 
    {
        if (vis[i]) continue;//如果已经算过就不再算了
        vis[i] = 1;//如果i这个结构体是第一个放在直线里的结构体,那么它需要一条光线就不用减了。
        for (int j = i + 1; j < n; j++) 
        {
            x = a[i]; x1 = a[j]; y = b[i]; y1 = b[j]; z = c[i]; z1 = c[j];
            if (x * y1 == x1 * y && x * z1 == x1 * z && y * z1 == y1 * z) 
            {
                ans--;
                vis[j] = 1;//后边的向量如果跟前面某个向量平行,答案数值就减且仅减一次
            }
        }
    }
    cout << ans;
    return 0;
}

J - Jeronimo's List

快排不行,上桶排!

#include <iostream>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=3e7+10;
ll a[N],tmp[N];
signed main()
{
    ll n,ma=-1,mi=99999999,k=1;
    int m,q;
    scanf("%lld%d%d",&n,&m,&q);
    for (int i=1; i<=m; i++)
    {
        scanf("%lld",&a[i]);
        tmp[a[i]]++;
        ma=max(ma,a[i]);
        mi=min(mi,a[i]);
    }
    for (int i=m+1; i<=n; i++)
    {
        a[i]=(a[i-m+1]+a[i-m])%30000000;
        tmp[a[i]]++;
        ma=max(ma,a[i]);
        mi=min(mi,a[i]);
    }
    for(int i=mi; i<=ma; i++)
    {
        for(int j=1; j<=tmp[i]; j++)
            a[k++]=i;
    }
    while (q--)
    {
        ll x;
        scanf("%lld",&x);
        printf("%lld\n",a[x]);
    }
    return 0;
}

 

posted @ 2022-05-27 19:12  好腻友Π  阅读(39)  评论(0)    收藏  举报