# 2017中国大学生程序设计竞赛 - 女生专场

1.HDU-6023

#include<cstdio>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<iostream>

using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
const int maxn = 20;
const int maxm = 1e3+10;
int n,m;
int cnt[maxn];
int ac[maxn];
int ans[maxn];

int main()
{
int T;
scanf("%d",&T);
while( T--)
{
mem(ac,0);
mem(cnt,0);
mem(ans,0);
scanf("%d%d",&n,&m);
int pro,hour,minu;
char res[5];
while( m--)
{
scanf("%d%d:%d%s",&pro,&hour,&minu,res);
if( !ac[pro-1000])
{
if( strcmp(res,"AC") == 0)
{
ac[pro-1000] = 1;
ans[pro-1000] = cnt[pro-1000]*20+hour*60+minu;
}
else
{
cnt[pro-1000]++;
}
}
}
int accept = 0;
int result = 0;
for( int i = 1; i <= n; i++)
{
if( ac[i])
{
accept++;
result += ans[i];
}
}

printf("%d %d\n",accept,result);
}

return 0;
}

2.HDU-6024

#include<cstdio>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<iostream>

using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int maxn = 3e3+10;
int n;
struct classroom{
ll p,c;
};
classroom cr[maxn];
ll dp[maxn][2];
ll sum[maxn];//前缀和

bool cmp( classroom cr1, classroom cr2)
{
return cr1.p < cr2.p;
}

int main()
{
while( ~scanf("%d",&n))
{
mem(dp,inf);
mem(sum,0);
for( int i = 1; i <= n; i++)
scanf("%lld%lld",&cr[i].p,&cr[i].c);
sum[0] = 0;
sort(cr+1,cr+n+1,cmp);
for( int i = 1; i <= n; i++)
sum[i] = sum[i-1]+cr[i].p;

dp[1][0] = inf;
dp[1][1] = cr[1].c;
for( int i = 2; i <= n; i++)
{
for( int j = 1; j < i; j++)
{
dp[i][0] = min(dp[i][0],dp[j][1]+(sum[i]-sum[j]-(ll)(i-j)*cr[j].p));
}
//            ll t = 0;
//            for( int j = i-1; j > 0; j--)
//            {
//                t += (i-j)*(cr[j+1].p-cr[j].p);
//               dp[i][0] = min(dp[i][0],dp[j][1]+t);
//            }
dp[i][1] = min(dp[i-1][0],dp[i-1][1])+cr[i].c;
}
printf("%lld\n",min(dp[n][0],dp[n][1]));
}

return 0;
}

3.HDU-6025

#include<cstdio>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<iostream>

using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
const int maxn = 1e5+10;
int n;
int a[maxn];

int main()
{
int T;
scanf("%d",&T);
while( T--)
{
scanf("%d%d",&n,&a[0]);
int gcd = a[0];
for( int i = 1; i < n; i++)
{
scanf("%d",&a[i]);
gcd = __gcd(gcd,a[i]);
}
int cnt = 0;
int tmp = a[0];
if( tmp == gcd)
{
cnt = 1;
tmp = a[1];
}

for( int i = 1; i < n; i++)
{
if( cnt == 1)
{
tmp = __gcd(tmp,a[i]);
}
else
{
if( __gcd(tmp,a[i]) == gcd)
{
cnt = 1;;
}
else
tmp = __gcd(tmp,a[i]);
}
}
printf("%d\n",tmp);
}

return 0;
}

4.HDU-6026

5.HDU-6027

#include<cstdio>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<iostream>

using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
const ll mod = 1000000007;
ll n,k;
ll ans;

ll cal( ll a, ll k)
{
if( k == 0)
return 1;
ll res = a;
for( int i = 1; i < k; i++)
{
res = res*a;
res %= mod;
}
return res;
}

int main()
{
int T;
scanf("%d",&T);
while( T--)
{
ans = 0;
scanf("%lld%lld",&n,&k);
for( int i = 1; i <= n; i++)
{
ans += cal(i,k);
ans %= mod;
}
printf("%lld\n",ans%mod);
}

return 0;
}

6.HDU-6028

0ac= =

7.HDU-6029

#include<cstdio>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<iostream>

using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
const int maxn = 1e5+10;
int n;
int cnt;

int main()
{
int T;
scanf("%d",&T);
while( T--)
{
scanf("%d",&n);
int tmp = n;
cnt = 1;
int x;
while( tmp > 1)
{
scanf("%d",&x);
if( x == 1)
cnt = max(cnt-1,0);
else
cnt++;
tmp--;
}
if( n%2)
{
puts("No");
continue;
}
if( cnt == 0)
puts("Yes");
else
puts("No");
}

return 0;
}

8.HDU-6030

a[i]=a[i-1]+c[i-1],b[i]=a[i-1],c[i]=b[i-1]，我们以S[i]表示满足条件的种类数，s[i]=a[i]+b[i]+c[i]，我们通过对上面的式子化简，可以得到s[n]=s[n-1]+s[n-3]，题目给出的n高达1e18，直接递推无法的到结果，要用到矩阵快速幂。

1 0 1

1 0 0

0 1 0

#include<cstdio>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<iostream>

using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
const ll mod = 1000000007;
ll n;
ll a[4] = {0,2,3,4};
struct mat{
ll a[3][3];
};
mat ini = { 1,0,1,1,0,0,0,1,0};

mat MatMul( mat x, mat y)
{
mat res;
mem(res.a,0);
for( int  i = 0; i < 3; i++)
{
for( int j = 0; j < 3; j++)
{
for( int k = 0; k < 3; k++)
{
res.a[i][j] += (x.a[i][k]*y.a[k][j])%mod;
res.a[i][j] %= mod;
}
}
}
return res;
}

mat MatPow( ll n)
{
mat c,res;
c.a[0][0] = c.a[0][2] = c.a[1][0] = c.a[2][1] = 1;
c.a[0][1] = c.a[1][1] = c.a[1][2] = c.a[2][0] = c.a[2][2] = 0;
res.a[0][0] = res.a[1][1] = res.a[2][2] = 1;
res.a[0][1] = res.a[0][2] = res.a[1][0] = res.a[1][2] = res.a[2][0] = res.a[2][1] = 0;
while( n)
{
if( n%2)
res = MatMul(res,c);
c = MatMul(c,c);
n >>= 1;
}

return res;
}

int main()
{
int T;
scanf("%d",&T);
while( T--)
{
scanf("%lld",&n);
if( n < 4)
printf("%lld\n",a[n]);
else
{
mat res = MatPow(n-3);
printf("%lld\n",(res.a[0][0]*a[3]%mod+res.a[0][1]*a[2]%mod+res.a[0][2]*a[1]%mod)%mod);
}
}

return 0;
}

9.HDU-6031

10.HDU-6032