标签:scanf class 个人感受 for cstring 分享 -- amp es2017
个人感受:这套题目,跪在了最后一道题,想了许久,应该是7:40左右开始想的,想了斜率优化之类的,但是最后没有拿更多的分数,实在是失策。
三道题100+100+50
nbc
1 #include<cstdio> 2 #include<algorithm> 3 #include<cmath> 4 #include<cstring> 5 #include<iostream> 6 #define mod 1000000007 7 8 using namespace std; 9 10 int n; 11 12 long long ksm(long long a,long long b) 13 { 14 long long ans=1; 15 while (b) 16 { 17 if (b%2==1) ans=ans*a%mod; 18 a=a*a%mod; 19 b/=2; 20 } 21 return ans; 22 } 23 int main() 24 { 25 freopen("nbc.in","r",stdin); 26 freopen("nbc.out","w",stdout); 27 28 scanf("%d",&n); 29 if (n==1) printf("1\n"); 30 else 31 { 32 long long y=ksm(2,n-1); 33 long long x=((n-1)*y+1)%mod; 34 long long ans=x*ksm(y,mod-2)%mod; 35 printf("%lld\n",ans); 36 37 } 38 }
original
1 #include<cstdio> 2 #include<algorithm> 3 #include<cmath> 4 #include<iostream> 5 #include<cmath> 6 #define NN 100007 7 #define MM 200007 8 9 using namespace std; 10 11 int n,m; 12 long long k; 13 int fa[NN],size[NN]; 14 struct Node 15 { 16 int x,y,z; 17 }a[MM]; 18 19 bool cmp(Node x,Node y) 20 { 21 return x.z>y.z; 22 } 23 int find(int num) 24 { 25 if (fa[num]!=num) fa[num]=find(fa[num]); 26 return fa[num]; 27 } 28 int main() 29 { 30 freopen("original.in","r",stdin); 31 freopen("original.out","w",stdout); 32 33 scanf("%d%d%lld",&n,&m,&k); 34 for (int i=1;i<=m;i++) 35 scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z); 36 sort(a+1,a+m+1,cmp); 37 for (int i=1;i<=n;i++) 38 { 39 fa[i]=i; 40 size[i]=1; 41 } 42 long long ans=0; 43 for (int i=1;i<=m;i++) 44 { 45 int x=find(a[i].x),y=find(a[i].y); 46 if (x==y) continue; 47 ans=ans+(long long)size[x]*size[y]; 48 if (ans>=k) 49 { 50 printf("%d\n",a[i].z); 51 return 0; 52 } 53 fa[y]=x; 54 size[x]+=size[y]; 55 } 56 }
string
1 #include<cstdio> 2 #include<algorithm> 3 #include<iostream> 4 #include<cmath> 5 #include<cstring> 6 #define LL long long 7 #define NN 2007 8 #define INF 1e16+7 9 10 using namespace std; 11 12 int n,a,b,c,d,l,r; 13 LL f[NN],dif[NN],sum[NN]; 14 bool boo[NN][NN]; 15 char ch[NN]; 16 17 void prepare() 18 { 19 scanf("%d%d%d%d%d%d%d",&n,&a,&b,&c,&d,&l,&r); 20 scanf("%s",ch+1); 21 for (int i=1;i<=n;i++) 22 { 23 int mx=0,k[27]={0}; 24 for (int j=i;j<=n;j++) 25 { 26 int t=ch[j]-‘a‘; 27 k[t]++; 28 if (k[t]>mx) mx=k[t]; 29 if (mx>=l&&mx<=r) boo[i][j]=true; 30 } 31 } 32 for (int i=1;i<=n;i++) 33 { 34 scanf("%lld",&dif[i]); 35 sum[i]=sum[i-1]+dif[i]; 36 } 37 } 38 LL fc(LL x) 39 { 40 return (LL)a*x*x+b; 41 } 42 LL fk(LL x) 43 { 44 return (LL)c*x+d; 45 } 46 int main() 47 { 48 freopen("string.in","r",stdin); 49 freopen("string.out","w",stdout); 50 51 prepare(); 52 53 for (int i=1;i<=n;i++) 54 { 55 f[i]=INF; 56 for (int j=i-1;j>=0;j--) 57 { 58 f[i]=min(f[i],f[j]+fc(sum[i]-sum[j])); 59 if (boo[j+1][i]) f[i]=min(f[i],f[j]+fk(sum[i]-sum[j])); 60 } 61 printf("%lld\n",f[i]); 62 } 63 }
标签:scanf class 个人感受 for cstring 分享 -- amp es2017
原文地址:http://www.cnblogs.com/fengzhiyuan/p/7522557.html