比赛链接:http://acm.bnu.edu.cn/v3/contest_show.php?cid=5727
手速不够。。。简直了啊
A:大神们说打表找规律,然后就可以得到了。
<span style="font-size:18px;">#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);
#define mod 1000000007
const int maxn = 1000010;
char str[maxn];
using namespace std;
int dp[maxn];
struct node
{
int a, b;
}f[maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n, k;
cin >>n>>k;
if(n%2)
{
if((k-1)%4 < 2) puts("B");
else puts("A");
}
else
{
if(k%2) puts("F");
else if(k%4 == 0) puts("A");
else puts("B");
}
}
}</span>
B:大水题,(n-1)/n,分数要化简到最简式。
<span style="font-size:18px;">#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);
#define mod 1000000007
const int maxn = 210;
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
LL n;
scanf("%lld",&n);
LL m = (n-1LL);
LL t = __gcd(n, m);
cout<<m/t<<"/"<<n/t<<endl;
}
}</span>
C:比赛的时候猜了一下没敢交。。。后来才发现是对的啊。。。
什么都不加的话先手必胜,加了的话会构成环,如果是奇数环的话从第一个开始取先手必胜,偶数的环的话,先把环拆开,然后先手再取最大的可以必胜。总之,先手必胜。
<span style="font-size:18px;">#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);
const int maxn = 210;
using namespace std;
int main()
{
int T;
cin >>T;
while(T--)
{
int n, m;
int x, y;
cin >>n>>m;
for(int i = 0; i < m; i++) scanf("%d %d",&x, &y);
puts("Bill will lose HAHA");
}
return 0;
}
</span>
D:矩阵加速递推,水题做的太慢到这里没时间了啊。。sad
f(x)代表发育期;
g(x)代表更年期;
h(x)代表天数;
f(x) = y*g(x-1)+h(x-1)*p;
g(x) = x*f(x-1)+z*g(x-1);
h(x) = h(x-1)+1;
从:f(x-1) g(x-1) h(x-1) 1 到 f(x) g(x) h(x) 1
关系矩阵:
0 y p 0
x z 0 0
0 0 1 1
0 0 0 1
<span style="font-size:18px;">#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);
const int maxn = 210;
using namespace std;
struct matrix
{
LL f[10][10];
};
matrix mul(matrix a, matrix b, int n)
{
matrix c;
memset(c.f, 0, sizeof(c.f));
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
for(int k = 0; k < n; k++) c.f[i][j] += a.f[i][k]*b.f[k][j];
c.f[i][j];
}
}
return c;
}
matrix pow_mod(matrix a, LL b, int n)
{
matrix s;
memset(s.f, 0 , sizeof(s.f));
for(int i = 0; i < n; i++) s.f[i][i] = 1LL;
while(b)
{
if(b&1) s = mul(s, a, n);
a = mul(a, a, n);
b >>= 1;
}
return s;
}
matrix Add(matrix a,matrix b, int n)
{
matrix c;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
c.f[i][j] = a.f[i][j]+b.f[i][j];
c.f[i][j];
}
}
return c;
}
int main()
{
int T;
cin >>T;
while(T--)
{
LL x, y, z, p, n;
cin >>x>>y>>z>>p>>n;
matrix c;
memset(c.f, 0 ,sizeof(c.f));
c.f[0][0] = 0;
c.f[0][1] = y;
c.f[0][2] = p;
c.f[0][3] = 0;
c.f[1][0] = x;
c.f[1][1] = z;
c.f[1][2] = 0;
c.f[1][3] = 0;
c.f[2][0] = 0;
c.f[2][1] = 0;
c.f[2][2] = 1;
c.f[2][3] = 1;
c.f[3][0] = 0;
c.f[3][1] = 0;
c.f[3][2] = 0;
c.f[3][3] = 1;
matrix d = pow_mod(c, n, 4);
LL sum = 0LL;
sum += d.f[0][3];
sum += d.f[1][3];
printf(">>%lld\n",sum);
}
return 0;
}
</span>
E:就是一个活动排序,大水题。
<span style="font-size:18px;">#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);
#define mod 1000000007
const int maxn = 210;
using namespace std;
typedef struct sss
{
int start_time;
int end_time;
} s;
bool operator <(s a, s b)
{
return a.end_time < b.end_time;
}
int main()
{
int T;
cin >>T;
int n;
while(T--)
{
cin>>n;
int timestart = 0;
vector<s> a;
while(n--)
{
s temp;
cin>>temp.start_time>>temp.end_time;
a.push_back(temp);
}
sort(a.begin(),a.end(),less<s>());
int count = 0;
for(vector<s>::iterator ite = a.begin(); ite != a.end(); ++ite)
{
if((*ite).start_time > timestart)
{
count++;
timestart = (*ite).end_time;
}
}
cout<<count<<endl;
//a.clear();
}
}</span>
F:读懂题之后就是一个标准的01背包了啊。
PS:代码写了1234B好巧啊。
<span style="font-size:18px;">#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);
#define mod 1000000007
const int maxn = 1000010;
char str[maxn];
using namespace std;
int dp[maxn];
struct node
{
int a, b;
}f[maxn];
int main()
{
int T;
scanf("%d",&T);
int Case = 1;
while(T--)
{
int A, B, n;
scanf("%d %d %d",&A, &B, &n);
for(int i = 0; i < n; i++) scanf("%d",&f[i].a);
for(int i = 0; i < n; i++) scanf("%d",&f[i].b);
memset(dp, 0, sizeof(dp));
for(int i = 0; i < n; i++)
{
for(int j = A; j >= 0; j--)
{
if(j-f[i].a < 0) break;
dp[j] = max(dp[j], dp[j-f[i].a]+f[i].b);
}
}
printf("Case #%d: ",Case++);
if(dp[A] >= B) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
</span>
G:分大圆里面,小圆里面。分别推一下公式就可以了啊,小圆里面我是先求交点又推的公式。
<span style="font-size:18px;">#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);
#define mod 1000000007
const int maxn = 1000010;
char str[maxn];
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
LL n;
cin >>n;
if(!n)
{
cout<<2<<endl;
continue;
}
if(n == 1)
{
cout<<4<<endl;
continue;
}
LL y = 2*n;
y += (n+1)*n/2+1;
///if(n == 2) y++;
cout<<y<<endl;
}
}</span>
H:一个水题,结果错了好多遍啊。读题不认真啊。sad。。。
注意:i为偶数时i只能和i-1匹配。
<span style="font-size:18px;">#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);
#define mod 1000000007
const int maxn = 1000010;
char str[maxn];
using namespace std;
bool judge(char x, char y)
{
if(x == 'a' && y == 'b' || x == 'b' && y == 'a') return 1;
if(x == 'c' && y == 'd' || x == 'd' && y == 'c') return 1;
if(x == 'e' && y == 'f' || x == 'f' && y == 'e') return 1;
if(x == 'g' && y == 'h' || x == 'h' && y == 'g') return 1;
if(x == 'i' && y == 'j' || x == 'j' && y == 'i') return 1;
if(x == 'k' && y == 'l' || x == 'l' && y == 'k') return 1;
if(x == 'm' && y == 'n' || x == 'n' && y == 'm') return 1;
if(x == 'o' && y == 'p' || x == 'p' && y == 'o') return 1;
if(x == 'q' && y == 'r' || x == 'r' && y == 'q') return 1;
if(x == 's' && y == 't' || x == 't' && y == 's') return 1;
if(x == 'u' && y == 'v' || x == 'v' && y == 'u') return 1;
if(x == 'w' && y == 'x' || x == 'x' && y == 'w') return 1;
if(x == 'y' && y == 'z' || x == 'z' && y == 'y') return 1;
return 0;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",str);
int len = strlen(str);
char sx[maxn];
int top = 0;
for(int i = 0; i < len; i++)
{
if(!top)
{
sx[top++] = str[i];
continue;
}
if(abs(str[i]-sx[top-1]) == 1 && judge(str[i], sx[top-1])) top--;
else sx[top++] = str[i];
}
sx[top] = '\0';
if(!top)
{
puts("sad!");
continue;
}
puts(sx);
}
}</span>