SDUT 2022 Summer Individual Contest - 8 (补题)

题目链接:

Problem - H - Codeforces

题意:

给出一个多边形的边数和边长,求这个多边形的外接圆面积。

分析:

好久没有做过几何的题目了,虽然不是很难,拿本题重拾一下做题记忆

取多边形其中一条边,连接两点至圆心形成三角形有以下关系:

#include <bits/stdc++.h>
#define endl '\n'
#define x first
#define y second
#define PI acos(-1)
#define SugarT ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

const int N=1e5+10;
const int M=510;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const double eps = 1e-6;

void solve()
{
    double n,x;
    cin >> n >> x;
    x=x*1.0/2;
    double k=PI*1.0/n;
    double ans=x/tan(k);
    ans=PI*(x*x+ans*ans);
    printf("%.9lf",ans);
}

int main()
{
    SugarT
    int T=1;
        //cin >> T;
    while(T--)
        solve();

    return 0;
}

 


题目链接:

 Problem - I - Codeforces

题意:

n个人每个人都有一个boss,只有老板自己没有,依次输出第i个人的boss。4(2)的意思是2的boss是4

(n的值可能是多位数,这需要判断。)

分析:

典中典栈模拟,比较难写的还是判断数的位数

#include <bits/stdc++.h>
#define endl '\n'
#define x first
#define y second
#define PI acos(-1)
#define SugarT ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

const int N=1e6+10;
const int M=510;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const double eps = 1e-6;

int n;
string s;
int ans[N];

int check(int i)
{
    int res=s[i++]-'0';
    while(s[i]>='0' && s[i]<='9')
    {
        res=res*10+s[i]-'0';
        i++;
    }
    return res;
}

int ne(int i)
{
    while(s[i]<='9' && s[i]>='0')i++;
    return i;
}

void solve()
{
    cin >> n >> s;
    stack<int> q;
    int x=check(0);
    q.push(x);
    int k=ne(0);
    for(int i=k;i<s.size();i++){
        if(s[i]==')'){
            int t=q.top();
            q.pop();
            ans[t]=q.top();
        }
        else if(s[i]<='9' && s[i]>='0'){
            int x=check(i);
            q.push(x);
            i=ne(i)-1;
        }
    }
    for(int i=1;i<=n;i++)cout << ans[i] << " ";
}

int main()
{
    SugarT
    int T=1;
        //cin >> T;
    while(T--)
        solve();

    return 0;
}

题目链接:

 Problem - K - Codeforces

题意:

求数组所有非空自己的异或和

分析:

运用二进制遍历的方法求得所有子集的解,相加即可(开 long long)

#include <bits/stdc++.h>
#define endl '\n'
#define x first
#define y second
#define int long long 
#define PI acos(-1)
#define SugarT ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

const int N=1e5+10;
const int M=510;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const double eps = 1e-6;

int q[25];

void solve()
{
    int n;
    int ans=0;
    cin >> n;
    for(int i=0;i<n;i++)cin >> q[i];
    for(int i=0;i<2<<n-1;i++)
    {
        int x=0;
        for(int j=0;j<n;j++)
            if(i>>j&1)x|=q[j];
        ans+=x;
    }
    cout << ans << endl;
}

signed main()
{
    SugarT
    int T=1;
        //cin >> T;
    while(T--)
        solve();

    return 0;
}

posted @ 2022-07-14 15:48  MrSugarT  阅读(49)  评论(0编辑  收藏  举报