A.Live love
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m;
int main(){
int t;
cin>>t;
while(t--){
cin>>n>>m;
if(m==0){
cout<<"0"<<" "<<"0"<<endl;
continue;
}
else if(n==m){
cout<<m<<" "<<m<<endl;
continue;
}
else{
cout<<m<<" ";
int k=n/2;
if(m<=k){
cout<<"1"<<endl;
continue;
}
k=n-m+1;
int t=m/k;
if(m%k==0) cout<<t<<endl;
else cout<<t+1<<endl;
}
}
return 0;
}
C、Halting Problem
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
struct point{
string s;
int k,v;
};
int n;
point a[10010];
int vis[10010];
int main(){
int t;
cin>>t;
while(t--){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].s;
if(a[i].s=="add") cin>>a[i].v;
else cin>>a[i].v>>a[i].k;
}
int r=0;
int j=1;
int sum=0;
memset(vis,0,sizeof(vis));
while(1){
if(j>=n+1) break;
if(vis[j]>256) break;
if(a[j].s=="add"){
r=(r+a[j].v)%256;
vis[j]++;
j++;
}
if(j>=n+1) break;
if(vis[j]>256) break;
if(a[j].s=="beq"){
vis[j]++;
if(r==a[j].v) j=a[j].k;
else j++;
}
if(j>=n+1) break;
if(vis[j]>256) break;
if(a[j].s=="bne"){
vis[j]++;
if(r!=a[j].v) j=a[j].k;
else j++;
}
if(j>=n+1) break;
if(vis[j]>256) break;
if(a[j].s=="blt"){
vis[j]++;
if(r<a[j].v) j=a[j].k;
else j++;
}
if(j>=n+1) break;
if(vis[j]>256) break;
if(a[j].s=="bgt"){
vis[j]++;
if(r>a[j].v) j=a[j].k;
else j++;
}
if(j>=n+1) break;
if(vis[j]>256) break;
}
if(j>=n+1) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
K、XOR Clique
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int n;
int a[100010];
int b[32];
int cn[32];
int main(){
b[0]=1;
for(int i=1;i<=30;i++){
b[i]=(int)pow(2,i);
}
int t;
cin>>t;
while(t--){
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
memset(cn,0,sizeof(cn));
for(int j=0;j<30;j++){
for(int i=0;i<n;i++){
if(a[i]>=b[j] && a[i]<b[j+1]) cn[j]++;
}
}
int maxx=cn[0];
for(int j=0;j<=30;j++){
if(maxx<cn[j]) maxx=cn[j];
}
cout<<maxx<<endl;
}
return 0;
}