https://codeforces.com/gym/102411/problem/M
ICPC 2019-2020 North-Western Russia Regional Contest
//A #include#include using namespace std; int main(){ int a,b,n; int x,y,ans=0; scanf("%d%d%d",&a,&b,&n); x=(n-b)%(b-a); y=(n-b)/(b-a); if(x)x=3; else x=1; ans=2*y+x; printf("%d\n",ans); return 0; }
//E #include#include #define maxn 200010 using namespace std; int n,m,dep[maxn],head[maxn],num,a[maxn],fa[maxn]; struct node{ int to,pre; }e[maxn*2]; void Insert(int from,int to){ e[++num].to=to; e[num].pre=head[from]; head[from]=num; } void dfs(int now,int father){ dep[now]=dep[father]+1; fa[now]=father; for(int i=head[now];i;i=e[i].pre){ int to=e[i].to; if(to==father)continue; dfs(to,now); } } int main(){ freopen("Cola.txt","r",stdin); scanf("%d%d",&n,&m); int x,y; for(int i=1;i ){ scanf("%d%d",&x,&y); Insert(x,y); Insert(y,x); } for(int i=1;i<=m;i++)scanf("%d",&a[i]); if(m==1){ puts("YES"); printf("%d\n",a[1]); return 0; } dfs(a[1],0); int now=a[2]; for(int i=3;i<=m;i++){ if(dep[a[i]]>dep[now])now=a[i]; } int depx=(dep[a[1]]+dep[now])/2; if((dep[now]-dep[a[1]])%2!=0){ puts("NO"); return 0; } int depnow=dep[now]; while(depnow>depx){ now=fa[now]; depnow=dep[now]; } dfs(now,0); int dis=dep[a[1]]-1; for(int i=2;i<=m;i++){ if(dep[a[i]]-1!=dis){ puts("NO"); return 0; } } puts("YES"); printf("%d\n",now); return 0; }
//M //充满魔性的a了一发 #include#include #include #define maxn 2010 #define mod1 2353733 #define mod2 12377 using namespace std; int Case,n,a[maxn],b[maxn]; int tim[10000010]; long long ans; int Hash(int x){ return (1LL*x*107%mod1+1LL*x*23%mod1+1LL*x*37%mod1)%mod1; } int main(){ scanf("%d",&Case); while(Case--){ memset(tim,0,sizeof(tim)); ans=0; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); b[i]=a[i]*2; } for(int i=2;i //ö¾ÙÖмäÊýµÄλÖà int hs=Hash(a[i-1]); tim[hs]++; for(int j=i+1;j<=n;j++){ if(a[j]<b[i]){ int hsnow=Hash(b[i]-a[j]); ans=ans+tim[hsnow]; } } } cout< endl; } return 0; }