1003 Clockwise or Counterclockwise
题目:
https://vjudge.net/contest/389195#problem/C
思路:
相当于判断三个点的排列是顺时针还是逆时针,根据结论(x2-x1)(y3-y2)-(y2-y1)(x3-x2)>0,则为逆时针。
代码:
using namespace std;
typedef long long ll;
int T;
ll xa,xb,ya,yb,xc,yc;
int main(){
scanf("%d",&T);
while(T--){
scanf("%lld %lld %lld %lld %lld %lld",&xa,&ya,&xb,&yb,&xc,&yc);
if((xb-xa)*(yc-yb)-(yb-ya)*(xc-xb)>0){
printf("Counterclockwise\n");
}else{
printf("Clockwise\n");
}
}
return 0;
}
1006 Fluctuation Limit
题目:
https://vjudge.net/contest/389195#problem/F
思路:
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int T;
int n,k;
int l[N],r[N];
int main(){
scanf("%d",&T);
while(T--){
scanf("%d %d",&n,&k);
for(int i=1;i<=n;i++){
scanf("%d %d",&l[i],&r[i]);
}
for(int i=1;i<n;i++){
l[i+1]=max(l[i+1],l[i]-k);//下限
r[i+1]=min(r[i+1],r[i]+k);//上限
}
for(int i=n;i>1;i--){
l[i-1]=max(l[i-1],l[i]-k);//下限
r[i-1]=min(r[i-1],r[i]+k);//上限
}
bool ok=true;
for(int i=1;i<=n;i++){
if(l[i]>r[i])
ok=false;
}
if(ok){
printf("YES\n");
for(int i=1;i<=n;i++){
if(i==n){
printf("%d\n",l[i]);
}else{
printf("%d ",l[i]);
}
}
}else{
printf("NO");
}
}
return 0;
}
1009 Isomorphic Strings
题目:
https://vjudge.net/contest/389195#problem/I
思路:
代码:
//by Sshwy
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
int rnd(int p){return 1ll*rand()*rand()%p;}
int rnd(int L,int R){return rnd(R-L+1)+L;}
}
const int N=5e6+5,K=3,M=1e7+5;
int n;
char s[N];
int mod[K] = {
//1000003,
//1000037,
2000039,
5000011,
7000061
};
int hsh[K][N];
int pm[K][N];
int Hsh(int k,int l,int r){
return (hsh[k][r] - hsh[k][l-1]*1ll*pm[k][r-l+1] % mod[k] + mod[k]) % mod[k];
}
int ct = 0;
int tmp[M];
bool check(int k,int d){
++ct;
int cur = Hsh(k,1,d);
tmp[cur] = ct;
ROF(i,d,2){
cur = ((cur-(s[d-i+1]-'a'+1)*1ll*pm[k][d-1]) % mod[k] * 29ll % mod[k] + s[d-i+1]-'a'+1) % mod[k];
cur = (cur + mod[k]) % mod[k];
tmp[cur] = ct;
}
ROF(i,n/d-1,0){
int x = Hsh(k,i*d+1,i*d+d);
if(tmp[x] != ct)return 0;
}
return 1;
}
void go(){
scanf("%d",&n);
scanf("%s",s+1);
FOR(k,0,K-1){
FOR(i,1,n){
hsh[k][i] = (hsh[k][i-1]*29ll + s[i]-'a'+1) % mod[k];
}
}
FOR(d,1,n-1)if(n%d == 0){
bool flag = 1;
FOR(k,0,K-1){
if(check(k,d) == 0){
flag = 0;
break;
}
}
if(flag)return puts("Yes"), void();
}
puts("No");
}
int main(){
FOR(k,0,K-1){
pm[k][0] = 1;
FOR(i,1,N-1)pm[k][i] = pm[k][i-1] * 29ll % mod[k];
}
int t;
scanf("%d",&t);
FOR(i,1,t)go();
return 0;
}
比赛代码:https://paste.ubuntu.com/p/2yQDFDbNf3/