2013 whu暑假集训选拔#2

本文解析了几道ACM编程竞赛题目,包括括号匹配问题、最小正方形面积计算、质因数分解等,并提供了详细的算法思路及C++实现代码。

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

一、已AC的题
(没参加比赛)

二、赛后想想能过的题
A题
设立两个参数l和r
l表示当前位置‘{’的数量
r表示当前位置‘}’的数量
l == 0    '}'  r++
l == 0    '{'  l++
l > 0    '}'  l++
l > 0    '{'  l++
 当l > 1 && r > 1时(r>1表示在‘{’前有r个‘}’)
ans = (l+r+2)/2
其他情况是 (l+r)/2
#include <iostream>
#include <cstring>
using namespace std;

int l = 0, r = 0, ans, cas = 1;
string str;
int main()
{
    cin>>str;
    while(str[0] != '-')
    {
        for(int i = 0; i < (int)str.length(); i++)
        {
                if(l == 0)
                {
                     if(str[i] == '}') r++;
                     else l++;
                     continue;
                }
                if(l > 0)
                {
                     if(str[i] == '}') l--;
                     else l++;
                     continue;
                }
        }
        if(l >= 1 && r >= 1) ans = (r+1)/2 + (l+1)/2;
        else ans = l/2 + r/2;
        cout<<cas<<". "<<ans<<endl;
        cas++;
        l = r = 0;
        cin>>str;
    }

    return 0;
}


B题
题目说明略繁琐,注意boss的要求就行,实际就是求最小块的正方形面积,只需w和h除以他们之间的最大公约数,求乘积即可.

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define LL long long
#define abs(x)     ((x)>0?(x):-(x))
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, n)  for(int i = 0; i < n; i++)
using namespace std;

LL gcd(LL a, LL b){
    return b==0?a:gcd(b, a%b);
}
int main()
{
    LL w, h;
    while(scanf("%I64d%I64d", &w, &h) != EOF)
    {
        if(0 == w) break;
        LL t = gcd(w, h);
        printf("%I64d\n", (w/t)*(h/t));
    }
    return 0;
}



C题
质因数分解,打出1000内所有的质数,每个质数的指数取绝对值之和即距离,不同质数的个数即维度
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define LL long long
#define abs(x)     ((x)>0?(x):-(x))
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, n)  for(int i = 0; i < n; i++)
using namespace std;
int p[1010], x[1010], y[1010];
int len, n, m;
int cas = 1;
void prime() 
{
        for (int i = 2; i <= 1000; i ++) 
        {
            if (p[i] == -1) continue;
            p[len ++] = i;
            for (int j = 2; i * j <= 1000; j ++)
                p[i * j] = -1;
        }
}

int main() 
{
        prime();  
        //for (int i = 2; i <= 100; i ++)
//        cout<<p[i]<<" ";
        while (scanf("%d%d", &n, &m) != EOF) 
        {
            if (n == 0 && m == 0) break;
            int sum = 0, dis = 0;
            
            for (int i = 0; i < len; i ++) 
            {
                int a = 0, b = 0;
                while (n % p[i] == 0) a ++, n /= p[i];    
                while (m % p[i] == 0) b ++, m /= p[i];
                if (a | b) 
                {
                    sum ++;
                    dis += abs(a - b);
                }
            }
            if (n != 1) sum ++, dis ++;
            if (m != 1) sum ++, dis ++;
            if (n == m && n != 1) sum --, dis -= 2;
            printf("%d. %d:%d\n", cas, sum, dis);
            cas ++;
        }
        return 0;
}



D题
水的渣渣的题,看题说明写代码即可
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define LL long long
#define abs(x)     ((x)>0?(x):-(x))
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, n)  for(int i = 0; i < n; i++)
using namespace std;
int n, ans;
int cas = 1;
int main()
{
    while(scanf("%d", &n) && n != 0)
    {
       n = n*3;
       if(1 == n % 2)
       {
            n = (n+1)/2;
            n = 3*n;
            n = n/9;
            printf("%d. odd %d\n", cas, n);
            cas++;
            continue;
       }
       if(0 == n % 2)
       {
            n = (n+1)/2;
            n = 3*n;
            n = n/9;
            printf("%d. even %d\n", cas, n);
            cas++;
            continue;
       }
    }

    return 0;
}



F题
比较简单的计算几何,计算几何一直是弱项,最怕卡精度了。。。还得继续训练。。
#include <iostream>
#include <string>
#include <map>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
using namespace std;
const double PI = 3.141;
const double eps = 1e-8;
const int MAXN = 1024;

double dist(double &x1, double &y1, double &x2, double &y2)
{
	return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
int sgn(double x) {
    return (x > eps) - (x < -eps);
}
struct point
{
	double x, y;
	bool operator < (const point tp) const { return x < tp.x;}
}p[1005], c1, c2;

int main ()
{
	int n;
	int cas = 1;
	double T;
	while (scanf("%d", &n) != EOF)
	{
        if(n==0) break;
        scanf("%lf%lf%lf%lf%lf", &c1.x, &c1.y, &c2.x, &c2.y, &T);
        T /= PI;
        double x, y;
        for(int i=1; i<=n; i++) 
        {
            scanf("%lf%lf", &x, &y);
            p[i].x = (x-c1.x)*(x-c1.x)+(y-c1.y)*(y-c1.y);
            p[i].y = (x-c2.x)*(x-c2.x)+(y-c2.y)*(y-c2.y);
        }
        sort(p+1, p+n+1);
        int cur, ans = 0;
        p[0].x = 0;
        for(int i=0; i<=n; i++) 
        {
            x = p[i].x;
            y = T - x;
            if(sgn(y) < 0) break;

            cur = i;
            for(int j=i+1; j<=n; j++) 
            {
                if(sgn(y - p[j].y) >= 0) cur ++;
            }
            if(cur > ans) 
            {
                ans = cur;
            }
        }
        printf("%d. %d\n", cas++, n - ans);
	}
	return 0;
}


三、能力范围外的题

内容概要:该研究通过在黑龙江省某示范村进行24小时实地测试,比较了燃煤炉具与自动/手动进料生物质炉具的污染物排放特征。结果显示,生物质炉具相比燃煤炉具显著降低了PM2.5、CO和SO2的排放(自动进料分别降低41.2%、54.3%、40.0%;手动进料降低35.3%、22.1%、20.0%),但NOx排放未降低甚至有所增加。研究还发现,经济性和便利性是影响生物质炉具推广的重要因素。该研究不仅提供了实际排放数据支持,还通过Python代码详细复现了排放特征比较、减排效果计算和结果可视化,进一步探讨了燃料性质、动态排放特征、碳平衡计算以及政策建议。 适合人群:从事环境科学研究的学者、政府环保部门工作人员、能源政策制定者、关注农村能源转型的社会人士。 使用场景及目标:①评估生物质炉具在农村地区的推广潜力;②为政策制定者提供科学依据,优化补贴政策;③帮助研究人员深入了解生物质炉具的排放特征和技术改进方向;④为企业研发更高效的生物质炉具提供参考。 其他说明:该研究通过大量数据分析和模拟,揭示了生物质炉具在实际应用中的优点和挑战,特别是NOx排放增加的问题。研究还提出了多项具体的技术改进方向和政策建议,如优化进料方式、提高热效率、建设本地颗粒厂等,为生物质炉具的广泛推广提供了可行路径。此外,研究还开发了一个智能政策建议生成系统,可以根据不同地区的特征定制化生成政策建议,为农村能源转型提供了有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值