CodeForces 1162 D Chladni Figure 字符串

本文介绍了一种使用哈希思想判断由n个点和m条边组成的图形是否可以通过旋转获得相同图形的方法。通过将每个点的属性哈希成值,并在两倍长的数组中寻找重复的自身,实现图形旋转对称性的判断。

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

插眼

题意: 一个圆的边上平均放置了n个点, 这n个点连接了m条边, 问这个图形能不能顺时针旋转(0°,360°)得到相同的图形.

思路: 哈希的思想, 每个点都有自己的属性, 相隔x距离的另一个点给点a一条边就是a的一个属性, 把每个点的这些属性哈希成一个值, 所有点的值就会构成一个数组. 那么这个问题就变成能不能从2倍的这个数组中找到2次以上的它本身.(第一次是0°,第二次是360°,再有一次就是旋转x°得到对称图形.)

代码:

#include<bits/stdc++.h>
#define fuck(x) std::cout<<"["<<#x<<"->"<<x<<"]"<<endl;
using namespace std;

const int M=1e5+5;
const int inf=1e9+5;
const int mod=1e9+7;

vector<int>v[M];
int hx2[2*M];
int hx[M];

int nxt[M];
int n,m;

int KMP() {
    memset(nxt,0,sizeof(nxt));
    int la,lb;
    la=n;
    lb=m;
    int j,k;
    j=0;
    k=-1;
    nxt[0]=-1;
    while(j<la) {
        if(k==-1||hx[j]==hx[k]) {
            j++;
            k++;
            nxt[j]=k;
        } else {
            k=nxt[k];
        }
    }
    int ans=0;
    j=0;
    k=0;
    while(k<lb) {
        if(j==-1||hx[j]==hx2[k]) {
            j++;
            k++;
        } else {
            j=nxt[j];
        }
        if(j==la) {
            j=nxt[j];
            ans++;
        }
    }
    return ans;
}

int main() {
    int k;
    scanf("%d%d",&n,&k);
    m=2*n;
    for(int i=0; i<k; i++) {
        int a,b;
        scanf("%d%d",&a,&b);
        if(a>b)
            swap(a,b);
        v[a].push_back(min(b-a,n-b+a));//将一端为a点的边的长度放入a的vector
        v[b].push_back(min(b-a,n-b+a));
    }

    for(int i=0; i<n; i++) {
        //hx[i]为i点的属性,用n进制的一个数记录了vector中的数据
        sort(v[i+1].begin(),v[i+1].end());
        //这些数据是没有顺序的,只要两个点的vector集合相同,就是能够重合的点,所以要sort
        for(int j=0; j<v[i+1].size(); j++) {
            hx[i]=hx[i]*n+v[i+1][j];//自然溢出
        }
    }
    for(int i=0; i<n; i++) {
        hx2[i]=hx[i];
        hx2[i+n]=hx[i];
    }
    if(KMP()<=2) {//如果能够在hx2中匹配到2次以上的hx1,那么就能够旋转.
        printf("No\n");
    } else {
        printf("Yes\n");
    }

    return 0;
}

 

### Codeforces 1487D Problem Solution The problem described involves determining the maximum amount of a product that can be created from given quantities of ingredients under an idealized production process. For this specific case on Codeforces with problem number 1487D, while direct details about this exact question are not provided here, similar problems often involve resource allocation or limiting reagent type calculations. For instance, when faced with such constraints-based questions where multiple resources contribute to producing one unit of output but at different ratios, finding the bottleneck becomes crucial. In another context related to crafting items using various materials, it was determined that the formula `min(a[0],a[1],a[2]/2,a[3]/7,a[4]/4)` could represent how these limits interact[^1]. However, applying this directly without knowing specifics like what each array element represents in relation to the actual requirements for creating "philosophical stones" as mentioned would require adjustments based upon the precise conditions outlined within 1487D itself. To solve or discuss solutions effectively regarding Codeforces' challenge numbered 1487D: - Carefully read through all aspects presented by the contest organizers. - Identify which ingredient or component acts as the primary constraint towards achieving full capacity utilization. - Implement logic reflecting those relationships accurately; typically involving loops, conditionals, and possibly dynamic programming depending on complexity level required beyond simple minimum value determination across adjusted inputs. ```cpp #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<long long> a(n); for(int i=0;i<n;++i){ cin>>a[i]; } // Assuming indices correspond appropriately per problem statement's ratio requirement cout << min({a[0], a[1], a[2]/2LL, a[3]/7LL, a[4]/4LL}) << endl; } ``` --related questions-- 1. How does identifying bottlenecks help optimize algorithms solving constrained optimization problems? 2. What strategies should contestants adopt when translating mathematical formulas into code during competitive coding events? 3. Can you explain why understanding input-output relations is critical before implementing any algorithmic approach? 4. In what ways do prefix-suffix-middle frameworks enhance model training efficiency outside of just tokenization improvements? 5. Why might adjusting sample proportions specifically benefit models designed for tasks requiring both strong linguistic comprehension alongside logical reasoning skills?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值