A.分不分
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
int T,cas = 1,x;
cin>>T;
while(T--){
cin>>x;
printf("Case #%d:\n",cas++);
if(x%2==1){
cout<<x/2<<" "<<(x+1)/2<<endl;
}else{
int l = x/2-1,r = x/2+1;
while(__gcd(l,r)!=1){
l--;
r++;
}
cout<<l<<" "<<r<<endl;
}
}
}
B.橘猫与千层糕
#include <bits/stdc++.h>
#define MAXN 6
#define MAXM 200005
#define MOD 1000000007
#define ll long long
using namespace std;
ll dp[200005][6];
ll fuc[6][20];
ll bp[6];
ll getNum(ll x, ll y) {
if (y != 0 && x % 5 >= y) {
return x / 5 + 1;
}
return x / 5;
}
int main() {
int T, cas = 1;
ll a, b, n;
scanf("%d", &T);
while (T--) {
memset(dp, 0, sizeof(dp));
scanf("%lld %lld %lld", &n, &a, &b);
for (ll i = 0; i <= 4; i++) {
bp[i] = getNum(b, i) - getNum(a - 1, i);
}
dp[0][0] = 1;
ll tx = 1;
for (ll i = 1; i <= n; i++) {
for (ll j = 0; j < 5; j++) {
for (ll k = 0; k < 5; k++) {
dp[i][j] = (dp[i][j] + (dp[i - 1][(j - k + 5) % 5] * bp[k]) % MOD) % MOD;
}
}
tx = (tx * i) % MOD;
}
printf("Case #%d:\n", cas++);
printf("%lld\n", (dp[n][0]) % MOD);
}
}
C.橘猫吃千层糕
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[1000000];
int main(){
int ans = 1,n;
while(cin>>n){
for(int i = 0 ; i < n ; i++){
cin>>a[i];
}
sort(a, a+n);
printf("Case #%d:\n",ans++);
if(n % 2 == 0){
printf("%.2lf\n", 1.0 * (a[n/2-1] + a[n/2]) / 2);
}else{
printf("%.2lf\n", 1.0 * (a[n/2]));
}
}
}
D.Erwin Schrödinger的橘猫
#include<bits/stdc++.h>
using namespace std;
//对于字符串比较多的要统计个数的,map被卡的情况下,直接用字典树
//很多题都是要用到节点下标来表示某个字符串
const int maxn =2e6+5;//如果是64MB可以开到2e6+5,尽量开大
int tree[maxn][30];//tree[i][j]表示节点i的第j个儿子的节点编号
bool flagg[maxn];//表示以该节点结尾是一个单词
int tot;//总节点数
void insert_(char *str) {
int len=strlen(str);
int root=0;
for(int i=0; i<len; i++) {
int id=str[i]-'0';
if(!tree[root][id]) tree[root][id]=++tot;
root=tree[root][id];
}
flagg[root]=true;
}
bool find_(char *str) { //查询操作,按具体要求改动
int len=strlen(str);
int root=0;
for(int i=0; i<len; i++) {
int id=str[i]-'0';
if(!tree[root][id]) return false;
root=tree[root][id];
}
return true;
}
void init() { //最后清空,节省时间
for(int i=0; i<=tot; i++) {
flagg[i]=false;
for(int j=0; j<10; j++)
tree[i][j]=0;
}
tot=0;//RE有可能是这里的问题
}
int main() {
int T = 1,n,m;
char s[110];
tot = 0;
cin>>n;
for(int i = 0 ; i < n ; i++) {
cin>>s;
insert_(s);
}
cin>>m;
for(int i = 0 ; i < m ; i++) {
cin>>s;
printf("Case #%d:\n",T++);
if(find_(s)) {
cout<<"YES"<<endl;
} else {
cout<<"NO"<<endl;
}
}
init();
}