2018中国大学生程序设计竞赛 - 网络选拔赛(solve5/10)

博客围绕CCPC 2018的部分题目展开。涉及A题求n天交易最大收益和最小交换次数,用贪心和标记法求解;C题重写运算符号,利用费马小定理;D题判断a^n+b^n=c^n是否成立,依据费马大定理分情况求解。

题目链接:http://acm.hdu.edu.cn/listproblem.php?vol=55

A题

题意:给你n天,每天你到达一个地方,对于一个地方你可以买可以卖(前提你有东西),问你最后获得的最大的收益是多少,交换的最小次数是多少。

ps:如果没有交换次数跟https://blog.youkuaiyun.com/passer__/article/details/82055020就一样了。

思想:如果没有交换次数就贪心搞下,有了交换次数,就用flag标记下是否交换过,保存每组交换的最大的那个即可,最后交换次数等于最大的那个*2;

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
	ll valu;
	int flag;
	node(ll a,int b)
	{
		valu=a;
		flag=b;
	}
	friend operator < (node a,node b)
	{
		if(a.valu==b.valu)
			return a.flag<b.flag;
		return a.valu>b.valu; 
	}
};
priority_queue <node> p;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,t;
	ll temp;
	cin>>t;
	ll ans;
	while(t--)
	{
		cin>>n;
		ans=0;
		for(int i=0;i<n;i++)
		{
			cin>>temp;
			if(!p.empty())
			{
				node T=p.top();
				if(T.valu<temp)
				{
					ans=ans+(temp-T.valu);
					p.pop();
					p.push(node(temp,1));
				}
			}
			p.push(node(temp,0));
		}
		int sum=0;
		while(!p.empty())
		{
			node temp=p.top();
			if(temp.flag==1)
				sum++;
			p.pop(); 
		}
		cout<<ans<<" "<<sum*2<<endl;
	}
	return 0;
} 

C题

题意:就是让你重写+和*号的运算,然后让(m+n)^p=m^p+n^p;

通过费马小定理知道a^(p-1)≡1(mod p) 然后两边同时乘a 就变成a^p≡a(mod p)

(m+n)^p=(m%p+n%p)=(m+n)%p   同理乘法(m^p*n^p)=(m%p*n%p)  至于怎么证明一样多不会

#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,p;
	cin>>t;
	while(t--)
	{
		cin>>p;
		for(int i=1;i<=p;i++)
		{
			for(int j=1;j<=p;j++)
			{
				printf("%d",(i-1+j-1)%p);
				if(j!=p)
					printf(" ");
			}
			printf("\n");
		}
		for(int i=1;i<=p;i++)
		{
			for(int j=1;j<=p;j++)
			{
				printf("%d",((i-1)*(j-1))%p);
				if(j!=p)
					printf(" ");
			}
			printf("\n");
		}
	}
	return 0;
}

D题

题意:问你a^n+b^n=c^n是否成立,成立随意输出一组解,否则-1 -1

思想:费马大定理证明n>2 无解,所以考虑n<=2 

①n=0的时候肯定无解

②n=1 随便自己构造一组解即可

③n==2  通过a^2+b^2=c^2的a值奇偶数列法则 求解 证明:http://tieba.baidu.com/p/108936816

 

 

考虑a是奇数还是偶数对应上述2种不同的情况。

cin我T·····

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll t,n,a;
	scanf("%lld",&t);
	while(t--)
	{
		scanf("%lld%lld",&n,&a);
		if(n==0 || n>2)
			printf("-1 -1\n");
		else if(n==1)
			printf("1 %lld\n",a+1ll);	
		else
		{
			if(a%2==1)
			{
				ll temp=(a-1)>>1;
				printf("%lld %lld\n",2ll*temp*temp+2ll*temp,2ll*temp*temp+2ll*temp+1ll);
			}
			else
			{
				ll temp=a>>1;
				printf("%lld %lld\n",temp*temp-1ll,temp*temp+1ll);
			}
		}
	} 
	return 0;
}

 

 

I 题

J题

 

 

以下是我的运行脚本file/read-case "CFD_Analysis.cas.h5" file/cff-files yes file/start-transcript "log.trn" parallel/timer/reset define/models/steady yes define/models/viscous/kw-sst yes define/boundary-conditions/velocity-inlet inlet no no yes yes no 3.75 no 0 no yes 2 0.10 define/boundary-conditions/pressure-outlet outlet yes no 0 no yes no yes 2 0.10 yes no no define/overset-interfaces/create overset fluid-2 () fluid-1 () no solve/set/discretization-scheme/k 1 solve/set/discretization-scheme/omega 1 solve/set/discretization-scheme/momentum 1 solve/monitors/residual/convergence-criteria 1e-03 1e-03 1e-03 1e-03 1e-03 solve/initialize/hyb-initialization solve/iterate 100 define/models/unsteady-1st-order yes define/user-defined/compiled-functions compile "libudf" yes "UDF_VIV_Parallel.c" "" "" define/user-defined/compiled-functions load "libudf" define/dynamic-mesh/dynamic-mesh yes no no no no define/dynamic-mesh/controls/smoothing no define/dynamic-mesh/zones/create model rigid-body "UDF_MODEL::libudf" no no 0 0.004 0 fluid-1 constant 0 no no define/dynamic-mesh/zones/create fluid-1 rigid-body "UDF_OVERSET::libudf" no 0 0.004 0 define/dynamic-mesh/zones/create interior-fluid-1 rigid-body "UDF_OVERSET::libudf" no 0 0.004 0 fluid-1 constant 0 fluid-1 constant 0 no no solve/report-definitions/add report-drag drag thread-names model () scaled no quit solve/report-definitions/add report-lift lift thread-names model () scaled no quit solve/report-definitions/add report-moment moment thread-names model () scaled no quit solve/report-plots/add report-drag-rplot active yes report-defs report-drag () quit solve/report-plots/add report-lift-rplot active yes report-defs report-lift () quit solve/report-definitions/add report-y+ surface-vertexmax field y-plus surface-names model () quit define/custom-field-functions/define "courant-number" "dx_velocity_dx*delta_time<rd>" solve/report-definitions/add report-courant-number surface-vertexmax field courant-number surface-names model () quit solve/report-definitions/add cell-courant-number surface-vertexmax field cell-convective-courant-number surface-names model () quit solve/report-files/add report-output active yes file-name "Force_output.out" report-defs flow-time report-drag report-lift report-moment report-y+ report-courant-number () quit solve/set/reporting-interval 5 solve/set/time-step 0.001 solve/dual-time-iterate 1000 35 solve/set/transient-controls/fixed-periodic yes no 5.17578 1000 5 solve/dual-time-iterate 20 35 parallel/timer/usage file/stop-transcript exit yes
最新发布
12-22
在UDF和运行脚本检查无误的情况下,仿真结果振幅稳定为6MM,而实际实验振幅是3.8MM,可能有以下几方面原因: ### 物理模型方面 - **流体物性参数差异**:实际流体的物性参数(如密度、粘度等)可能与仿真中设定的参数存在差异。这些参数的不准确设定会影响流体的流动特性,进而影响涡激振动的振幅。例如,空气的密度会随温度、湿度和海拔高度变化,若仿真中使用的是标准大气条件下的空气密度,而实际实验环境不同,就可能导致仿真结果与实际不符[^1]。 - **结构参数误差**:结构的质量、刚度和阻尼等参数在实际和仿真中可能不一致。在UDF中,质量和阻尼比等参数是固定设定的,但实际结构可能由于材料特性、制造工艺等因素,其真实参数与设定值有偏差。如结构的实际阻尼比可能比仿真中设置的要大,从而使得实际振幅较小[^1]。 - **未考虑实际环境因素**:实际实验中,箱梁所处的环境可能存在一些复杂因素,如周围其他结构物的干扰、大气边界层的影响等。而在CFD仿真中,若没有充分考虑这些因素,可能会导致仿真结果与实际实验结果不一致。例如,周围其他建筑物的存在可能会改变箱梁周围的流场分布,从而影响涡振的振幅[^1]。 ### 数值算法方面 - **离散格式的影响**:离散格式的选择会影响数值计算的精度和稳定性。若采用的离散格式精度较低,可能会引入数值误差,导致仿真结果的振幅与实际实验振幅不一致。例如,一阶迎风格式虽然计算简单,但精度相对较低,在处理复杂的涡振问题时,可能无法准确捕捉涡结构的传播和演变,从而影响振幅的模拟结果[^1]。 ```python # 示例代码,在OpenFOAM中设置离散格式 # 设置二阶迎风格式 divSchemes { div(phi,U) Gauss linearUpwindV grad(U); } ``` - **时间步长设置不合理**:时间步长的大小对CFD模拟的稳定性和准确性有重要影响。如果时间步长过大,可能会导致数值计算不稳定,无法准确捕捉涡振的周期和振幅变化;如果时间步长过小,虽然可以提高计算精度,但会增加计算成本和计算时间。若时间步长设置不合理,就可能使仿真振幅与实际实验振幅出现偏差[^1]。 ### 边界条件方面 - **边界条件设置不准确**:边界条件的设置直接影响CFD模拟的结果。在二维箱梁涡振仿真中,入口边界条件、出口边界条件和壁面边界条件的设置若与实际实验情况不符,可能会导致仿真振幅与实际实验振幅不一致。例如,入口风速的大小和分布、出口压力的设置等,都可能会影响箱梁周围的流场分布,从而影响涡振的振幅[^1]。 ```python # 示例代码,在OpenFOAM中设置入口边界条件 # 设置入口速度 inlet { type fixedValue; value uniform (10 0 0); } ``` ### 实验误差方面 - **实验测量误差**:实际实验中,测量设备的精度、测量方法的准确性等都可能会引入误差。例如,位移传感器的精度有限,可能无法准确测量箱梁的微小振幅变化;实验环境的干扰也可能会影响测量结果的准确性。这些实验测量误差可能会导致实际实验振幅与CFD仿真振幅存在差异[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值