A
copy一个源文件会新产生一个源文件和一个副本,copy一个副本会新产生两个副本,现在有一个源文件,问能否copy出 x x 个副本和 个源文件?
瞎搞,注意一些特殊情况。
#include<cstdio>
using namespace std;
int x,y;
int main(){
freopen("A.in","r",stdin);
freopen("A.out","w",stdout);
scanf("%d%d",&x,&y);x-=y-1;
if (!y) return puts("No"),0;
if (x<0) return puts("No"),0;
if (y==1&&x) return puts("No"),0;
return puts((x&1)?"No":"Yes"),0;
}
B
问 (a,b,c),1≤a≤b≤c≤n,a xor b xor c=0 ( a , b , c ) , 1 ≤ a ≤ b ≤ c ≤ n , a x o r b x o r c = 0 且 a,b,c a , b , c 能组成三角形的三元组个数 (n≤2500) ( n ≤ 2500 ) 。
暴枚,枚举两个就行了。
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=2500;
int n,ans;
int main(){
freopen("B.in","r",stdin);
freopen("B.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++)
for (int j=i;j<=n;j++){
int k=i^j;if (k<j||k>n) continue;
ans+=i+j>k;
}
return printf("%d\n",ans),0;
}
C
问 1≤i<j≤k 1 ≤ i < j ≤ k 中是否存在 n mod i=n mod j(1≤n,k≤1018) n m o d i = n m o d j ( 1 ≤ n , k ≤ 10 18 ) 。
JYZdalao太强了,直接秒了此题。考虑枚举 j j ,当 时, n mod j n m o d j 只能为 0 0 ,当 时, n mod j n m o d j 只能为 1 1 ( 已经被占掉了),当 j=3 j = 3 时, n mod j n m o d j 只能为 2 2 ……以此类推,只要不存在 ,就说明存在 i,j i , j ,否则不存在。
直接枚举试试?惊奇的发现竟然过了?WHY?
观察满足上述条件的 n n ,发现只要加个 ,就满足 ∀(n+1) mod k=0 ∀ ( n + 1 ) m o d k = 0 了,也就是说 (n+1) mod [1,2,⋯,k]=0 ( n + 1 ) m o d [ 1 , 2 , ⋯ , k ] = 0 ,因为 [1,2,⋯,k] [ 1 , 2 , ⋯ , k ] 比较大啊,所以就不会TLE了。
#include<cstdio>
using namespace std;
typedef long long LL;typedef long double DB;
LL n,K;
int main(){
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
scanf("%lld%lld",&n,&K);bool fl=false;
for (int i=1;i<=K;i++)
if (n%i<i-1) {fl=true;break;}
return puts(fl?"No":"Yes"),0;
}
D
给出 n n 个由 和 h h 组成的串,一个串的价值 为 i<j,Si=s,Sj=h i < j , S i = s , S j = h 的 i,j i , j 个数。现在选择一种方案将 n n 个串接起来,求接起来的串的最大价值。
给两个串 定义优先级,如果 val(AB)>val(BA) v a l ( A B ) > v a l ( B A ) ,则 A A 的优先级高,然后按照这个优先级排序,因为 说明 A A 放在 前面更好(易证这个条件适用于全局),所以最后得到的是最大价值串。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=100000;
int n,S[maxn+5],H[maxn+5],ID[maxn+5];
char s[maxn+5];LL tot[maxn+5],ans;
inline bool cmp(const int &a,const int &b) {return (LL)S[a]*H[b]>(LL)S[b]*H[a];}
int main(){
freopen("D.in","r",stdin);
freopen("D.out","w",stdout);
for (int i=(scanf("%d",&n),1);i<=n;ID[i]=i,i++){
scanf("%s",s+1);int len=strlen(s+1);
for (int j=len;j;j--)
if (s[j]=='s') S[i]++,tot[i]+=H[i]; else H[i]++;
}
sort(ID+1,ID+1+n,cmp);int now=0;
for (int i=n;i;ans+=tot[ID[i--]]) ans+=(LL)S[ID[i]]*now,now+=H[ID[i]];
return printf("%lld\n",ans),0;
}