A题:水题
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main()
{
int t;
char s1[1005];
char s2[1005];
char ans1[1005];
char ans2[1005];
int len1, len2, pos1, pos2;
cin>>t;
while(t--)
{
cin>>s1>>s2;
len1 = strlen(s1);
len2 = strlen(s2);
pos1 = pos2 = 0;
ans1[pos1++] = s1[0];
for(int i = 1; i < len1; i++)
if(s1[i] != s1[i - 1])
ans1[pos1++] = s1[i];
ans2[pos2++] = s2[0];
for(int i = 1; i < len2; i++)
if(s2[i] != s2[i - 1])
ans2[pos2++] = s2[i];
ans1[pos1++] = 0;
ans2[pos2++] = 0;
if(strcmp(ans1, ans2) == 0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}
C题: 先把n质因数分解 然后容质就成
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int prime[1005];
int ans[100005];
int pos;
void fun1(int n)
{
pos = 0;
for(int i = 2; i * i<= n; i++)
if(n % i == 0)
{
prime[pos++] = i;
while(n % i == 0)
n /= i;
}
if(n > 1)
prime[pos++] = n;
}
long long fun2(long long n)
{
int num = 0;
ans[num++] = -1;
for(int i = 0; i < pos; i++)
{
int last = num;
for(int j = 0; j < last; j++)
ans[num++] = ans[j] * prime[i] * (- 1);
}
long long sum = 0;
for(int i = 1; i < num; i++)
sum += n/ans[i];
return sum;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
long long a, b;
cin>>a>>b>>n;
fun1(n);
cout<<(b - fun2(b) - (a - 1 - fun2(a - 1)))<<endl;
}
return 0;
}
F(x) 表示 x | gcd(a, b, c) 的满足条件的(a, b, c)的对数
#include <iostream>
#include <string.h>
using namespace std;
int isprime[100005];
int prime[100005];
int mu[100005];
int cnt;
void mobi(int n)
{
memset(isprime, 0, sizeof isprime);
mu[1] = 1;
cnt = 0;
for(int i = 2; i <= n; i++)
{
if(!isprime[i]){
prime[cnt++] = i;
mu[i] = -1;
}
for(int j = 0; j < cnt && i * prime[j] <= n; j++)
{
isprime[i * prime[j]] = 1;
if(i % prime[j]) mu[i * prime[j]] = -mu[i];
else{
mu[i * prime[j]] = 0;
break;
}
}
}
}
int main()
{
int t;
cin>>t;
mobi(100005);
while(t--)
{
int a, b;
cin>>a>>b;
long long tmp = a/b;
long long ans = 0;
for(int i = 1; i <= tmp; i++)
ans += 1ll * mu[i] * (tmp/i * (tmp/i - 1) * (tmp/i - 2) / 6);
cout<<ans<<endl;
}
return 0;
}
F题:水题
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int last[10005];
int ss[10005];
int pos;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i = 0; i < n; i++)
cin>>ss[i];
pos = 0;
last[pos++] = ss[0];
for(int i = 1; i < n; i++)
{
if(ss[i] >= last[0])
{
int j;
for(j = 1; j < pos; j++)
if(ss[i] < last[j]){
break;
}
last[j - 1] = ss[i];
}
else{
for(int i = pos; i >= 1; i--)
last[i] = last[i - 1];
last[0] = ss[i];
pos++;
}
}
cout<<pos<<endl;
}
return 0;
}
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
int ss[32];
int pos;
int main()
{
int t, n;
cin>>t;
while(t--)
{
cin>>n;
int ans = 0, cnt = 0, tmp;
for(int i = 0; i < n; i++)
{
cin>>tmp;
ans ^= tmp;
if(tmp >= 2) cnt++;
}
if(ans == 0)
{
if(cnt >= 2)
cout<<"Meidikeji_Shijiediyi!"<<endl;
else
cout<<"Yamato_Saikou!"<<endl;
}
else {
if(cnt == 0)
cout<<"Meidikeji_Shijiediyi!"<<endl;
else
cout<<"Yamato_Saikou!"<<endl;
}
}
return 0;
}
J题: 水题
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main()
{
int t;
int maxn = 0;
while(cin>>t)
{
int height[100005], width[100005];
maxn = 0;
for(int i = 0; i < t; i++)
{
cin>>height[i]>>width[i];
maxn = max(maxn, height[i]);
}
long long ans = 0;
for(int i = 0; i < t; i++)
{
ans += ((maxn + 1 - height[i]) * width[i]);
}
if(ans == 0) ans += 1;
cout<<ans<<endl;
}
return 0;
}