CC BY 4.0 (除特别声明或转载文章外)
如果这篇博客帮助到你,可以请我喝一杯咖啡~
Live Love
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<stdio.h>
int t,n,m;
int main()
{
for(scanf("%d",&t); t--;)
{
scanf("%d%d",&n,&m);
if(n==1||!m)printf("%d %d\n",m,m);
else for(int i=1,tmp,res; i<=m; ++i)
if(tmp=n/(i+1),res=n-tmp*(i+1),tmp*i+res>=m)
{
printf("%d %d\n",m,i);
break;
}
}
}
Halting Problem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<bits/stdc++.h>
using namespace std;
struct Instruction
{
char s[9];
int v,k,vis[256];
} a[10009];
int t,n,i,r;
int main()
{
for(scanf("%d",&t); t--;)
{
scanf("%d",&n);
for(i=1; i<=n; ++i)
{
fill(a[i].vis,a[i].vis+256,0);
scanf("%s%d",&a[i].s,&a[i].v);
if(a[i].s[1]!='d')scanf("%d",&a[i].k);
}
for(i=1,r=0; i<=n&&!a[i].vis[r]; ++i)
switch(a[i].vis[r]=1,a[i].s[1])
{
case 'd':
r=(r+a[i].v)%256;
break;
case 'e':
if(r==a[i].v)i=a[i].k-1;
break;
case 'n':
if(r!=a[i].v)i=a[i].k-1;
break;
case 'l':
if(r<a[i].v)i=a[i].k-1;
break;
case 'g':
if(r>a[i].v)i=a[i].k-1;
break;
}
printf(i>n?"Yes\n":"No\n");
}
}
Traveling on the Axis
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[100009];
ll t,ans;
int main()
{
for(scanf("%lld",&t); t--; printf("%lld\n",ans))
{
scanf("%s",s);
for(ll i=ans=0,n=strlen(s); i<n; ++i)
{
ans+=(i+1)*(n-i);
if(s[i]=='0')ans+=n-i;
if(i&&s[i]==s[i-1])ans+=i*(n-i);
}
}
}
XOR Clique
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<bits/stdc++.h>
using namespace std;
int t,n,a,k,cnt[31];
int main()
{
for(scanf("%d",&t); t--;)
{
fill(cnt,cnt+31,0);
for(scanf("%d",&n); n--;)
{
scanf("%d",&a);
for(k=0; a; ++k)a>>=1;
++cnt[k];
}
printf("%d\n",*max_element(cnt,cnt+31));
}
}