K
Each considered independently clearance, takes most value. For combinations for a title can be converted into the required minimum n, so the answer to half.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll input(){
ll x=0,f=0;char ch=getchar();
while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return f? -x:x;
}
const int N=1007;
#define PII pair<ll,ll>
#define fr first
#define sc second
#define mp make_pair
PII a[N];
ll ans[N];
ll get(ll a,ll x){
ll l=0,r=1e9,res=0;
while(l<=r){
ll mid=(l+r)/2;
if((2*a+mid+1)*mid/2<x) l=mid+1;
else res=mid,r=mid-1;
}
return res;
}
int main(){
ll a1=input(),a2=input();
int n=input();
ll Ans=0x3f3f3f3f3f3f3f;
for(int i=1;i<=n;i++){
a[i].fr=input(),a[i].sc=input();
ans[i]=get(a1,a[i].fr);
ans[i]=max(ans[i],get(a2,a[i].sc));
Ans=min(Ans,ans[i]);
}
printf("%lld\n",Ans);
}
H
Each number is deleted situation is equally likely, as long as Hu count how many sets of numbers on the list.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll input(){
ll x=0,f=0;char ch=getchar();
while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return f? -x:x;
}
int a=0,b;
int main(){
int n=input();
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
a+=__gcd(i,j)==1;
}
}
// cout<<a<<endl;
b=(n-1)/2*2+1;
if(a==0) b=1;
else{
int tmp=__gcd(a,b);
a/=tmp,b/=tmp;
}
printf("%d/%d\n",a,b);
}
G
For \ (k \ le nm \) case burst search line.
For \ (k> nm \) case the answer is clearly just find a Hamilton circuit to go, then the answer is clearly: \ (\ SUM A_ {I, J} + \ FRAC {((nm-. 1) nm)} {2} + (k-nm ) nm \)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll input(){
ll x=0,f=0;char ch=getchar();
while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return f? -x:x;
}
ll n,m,x,y,k;
ll a[15][15];
ll vis[15][15];
ll dfs(ll dep,ll tx,ll ty){
if(dep>=k) return 0;
if(tx<1||tx>n||ty<1||ty>m) return 0;
ll res=0,t=vis[tx][ty];
vis[tx][ty]=-(a[tx][ty]+dep);
res=max(dfs(dep+1,tx+1,ty),res);
res=max(dfs(dep+1,tx-1,ty),res);
res=max(dfs(dep+1,tx,ty+1),res);
res=max(dfs(dep+1,tx,ty-1),res);
vis[tx][ty]=t;
res+=a[tx][ty]+vis[tx][ty]+dep;
return res;
}
int main(){
n=input(),m=input();
x=input(),y=input();
k=input();
ll sum=0,Ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
a[i][j]=input();
vis[i][j]=0;
sum+=a[i][j];
}
}
if(k<n*m){
Ans=dfs(0,x,y);
}else{
Ans=sum+((n*m-1)*n*m)/2+(k-(n*m))*(n*m);
}
printf("%lld\n",Ans);
}