2016ACM/ICPC亚洲区沈阳站
emm,a出3题,补了两题
A,B水题
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define read(a) scanf("%d",&a) #define rread(a,b) scanf("%d%d",&a,&b) #define pii pair<int,int> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-7; const int N=200000+10,maxn=60000+10,inf=0x3f3f3f3f; int main() { int n; read(n); for(int i=0;i<n;i++) { int a,b; rread(a,b); printf("%d\n",2*max(a,b)+min(a,b)); } return 0; } /******************** ********************/
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define read(a) scanf("%d",&a) #define rread(a,b) scanf("%d%d",&a,&b) #define pii pair<int,int> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-7; const int N=200+10,maxn=60000+10,inf=0x3f3f3f3f; char s[N]; int main() { int n; read(n); for(int i=0;i<n;i++) { int a,b; scanf("%s",&s); int len=strlen(s),ans=0; for(int i=0;i<len;i++) { if(s[i]=='H')ans++; else if(s[i]=='C')ans+=12; else ans+=16; } printf("%d\n",ans); } return 0; } /******************** ********************/
C:递推,首先想到矩阵快速幂,构造一个7维的矩阵,分别是ai-1,ai-2,i^4,i^3,i^2,i,1,再转移下去
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define read(a) scanf("%d",&a) #define rread(a,b) scanf("%d%d",&a,&b) #define pii pair<int,int> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 2147493647 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-7; const int N=10+10,maxn=60000+10,inf=0x3f3f3f3f; struct Node{ int len; ll a[N][N]; }; Node mul(Node x,Node y) { Node ans; memset(ans.a,0,sizeof ans.a); ans.len=x.len; for(int i=0;i<x.len;i++) { for(int j=0;j<x.len;j++) { for(int k=0;k<y.len;k++) { ans.a[i][k]=(ans.a[i][k]+x.a[i][j]*y.a[j][k]%mod)%mod; } } } return ans; } Node quick_mul(Node x,ll n) { Node ans; memset(ans.a,0,sizeof ans.a); ans.len=x.len; for(int i=0;i<x.len;i++)ans.a[i][i]=1; while(n) { if(n&1)ans=mul(ans,x); x=mul(x,x); n/=2; } return ans; } int main() { int t; read(t); for(int i=0;i<t;i++) { ll n,x,y; scanf("%lld%lld%lld",&n,&x,&y); if(n==1) { printf("%lld\n",x%mod); continue; } if(n==2) { printf("%lld\n",y%mod); continue; } Node A; A.len=7; A.a[0][0]=1,A.a[0][1]=2,A.a[0][2]=1,A.a[0][3]=0,A.a[0][4]=0,A.a[0][5]=0,A.a[0][6]=0; A.a[1][0]=1,A.a[1][1]=0,A.a[1][2]=0,A.a[1][3]=0,A.a[1][4]=0,A.a[1][5]=0,A.a[1][6]=0; A.a[2][0]=0,A.a[2][1]=0,A.a[2][2]=1,A.a[2][3]=4,A.a[2][4]=6,A.a[2][5]=4,A.a[2][6]=1; A.a[3][0]=0,A.a[3][1]=0,A.a[3][2]=0,A.a[3][3]=1,A.a[3][4]=3,A.a[3][5]=3,A.a[3][6]=1; A.a[4][0]=0,A.a[4][1]=0,A.a[4][2]=0,A.a[4][3]=0,A.a[4][4]=1,A.a[4][5]=2,A.a[4][6]=1; A.a[5][0]=0,A.a[5][1]=0,A.a[5][2]=0,A.a[5][3]=0,A.a[5][4]=0,A.a[5][5]=1,A.a[5][6]=1; A.a[6][0]=0,A.a[6][1]=0,A.a[6][2]=0,A.a[6][3]=0,A.a[6][4]=0,A.a[6][5]=0,A.a[6][6]=1; A=quick_mul(A,n-2); ll ans=A.a[0][0]*y%mod; ans=(ans+A.a[0][1]*x%mod)%mod; ans=(ans+A.a[0][2]*3*3*3*3%mod)%mod; ans=(ans+A.a[0][3]*3*3*3%mod)%mod; ans=(ans+A.a[0][4]*3*3%mod)%mod; ans=(ans+A.a[0][5]*3%mod)%mod; ans=(ans+A.a[0][6]%mod)%mod; printf("%lld\n",ans); } return 0; } /******************** ********************/
G是个二分+积分题,由于关系找错了,导致一直没过,二分水平面和竖直的夹角,用积分求体积和,不倾斜的体积比较
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define read(a) scanf("%d",&a) #define rread(a,b) scanf("%d%d",&a,&b) #define pii pair<int,int> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 2147493647 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-7; const int N=100000+10,maxn=60000+10,inf=0x3f3f3f3f; double f(double x) { double y=acos(2*tan(x)-1); double a1,a2; a1=pi*cos(y)-y*cos(y)+sin(y)-(1.0/3.0)*sin(y)*sin(y)*sin(y); y=pi; a2=pi*cos(y)-y*cos(y)+sin(y)-(1.0/3.0)*sin(y)*sin(y)*sin(y); return (1.0/tan(x))*(a1-a2); } double bs(double x) { double l=0,r=pi/4; while(r-l>1e-10) { double m=(l+r)/2; if(f(m)>x)r=m; else l=m; } return l; } int main() { int t; scanf("%d",&t); for(int i=0;i<t;i++) { double d; scanf("%lf",&d); if(d<1e-6) { printf("%.5f\n",0.0); continue; } double ans=pi*sqrt(1+(2-d)*(2-d)); if(d<1) { double ang=bs(d*pi); double p=2*tan(ang),ang1=acos(1-p),v=ang1-(1-p)*sqrt(1-(1-p)*(1-p)); ans=v/sin(ang); } printf("%.5f\n",ans); } return 0; } /******************** ********************/
E,求点为m个的团有多少个,因为没学过最大团的算法,所以不敢写,补题的时候发现居然dfs就能过= =,直接暴力dfs找到含m个点的团就退出
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define read(a) scanf("%d",&a) #define rread(a,b) scanf("%d%d",&a,&b) #define pii pair<int,int> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 2147493647 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-7; const int N=100+10,maxn=60000+10,inf=0x3f3f3f3f; bool ok[N][N]; int contain[N],ans; int n,m,s; vector<int>v[N]; void dfs(int u,int a[],int sz) { if(sz==s) { ans++; return ; } for(int i=0;i<v[u].size();i++) { bool f=0; for(int j=0;j<sz;j++) { if(!ok[v[u][i]][a[j]]) { f=1; break; } } if(!f) { a[sz++]=v[u][i]; dfs(v[u][i],a,sz); sz--; } } } int main() { int t; read(t); for(int i=0;i<t;i++) { rread(n,m);read(s); for(int i=1;i<=n;i++)v[i].clear(); memset(ok,0,sizeof ok); while(m--) { int a,b; rread(a,b); if(a>b)swap(a,b); v[a].pb(b); ok[a][b]=ok[b][a]=1; } ans=0; for(int i=1;i<=n;i++) { // memset(contain,0,sizeof contain); contain[0]=i; dfs(i,contain,1); } printf("%d\n",ans); } return 0; } /******************** ********************/