2020hdu多校第八场比赛及补题

1003 Clockwise or Counterclockwise

给A B C三个点,这三个点都在一个以原点为圆心的圆上,问ABC方向是顺时针方向还是逆时针方向

挺烦的模拟

#include <bits/stdc++.h>
using namespace std;
#define int long long
// const int MAXN = ;
// const int MOD = ;
// const int INF = ;
// const double eps = ;
const double PI = acos(-1);
// const int DIRX[] = {};
// const int DIRY[] = {};

struct Node
{
    int x, y;
    double s;
    double c;
    double the;
}node[5];

int T;
double r;

int32_t main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> T;
    while (T--)
    {
        for (int i = 1; i <= 3; ++i)
        {
            cin >> node[i].x >> node[i].y;
            r = sqrt((long long)node[1].x * node[1].x + (long long) node[1].y * node[1].y);
            node[i].s = (double) node[i].y / r;
            node[i].c = (double) node[i].x / r;
            node[i].the = asin(node[i].s);
            // cout << node[i].s << " " << node[i].c << " " << node[i].the << endl;
        }
        for (int i = 1; i <= 3; ++i)
        {
            if (node[i].s > 0 && node[i].c < 0)
                node[i].the = PI - node[i].the;
            if (node[i].s <= 0 && node[i].c < 0)
                node[i].the = PI - node[i].the;
            if (node[i].s < 0 && node[i].c > 0)
                node[i].the += 2 * PI;
            // cout << (node[i].the / PI) << " ";
        }
        if (node[1].the > node[2].the)
        {
            if (node[3].the > node[1].the || node[3].the < node[2].the)
            {
                cout << "Clockwise" << endl;
            }
            else
            {
                cout << "Counterclockwise" << endl;
            }
        }
        else
        {
            if (node[3].the > node[2].the || node[3].the < node[1].the)
            {
                cout << "Counterclockwise" << endl;
            }
            else
            {
                cout << "Clockwise" << endl;
            }
        }
    }
    return 0;
}

  

 

1006 Fluctuation Limit

问是否存在这样一个数列,li ai ri (1 i n)   and  | ai ai+1 | k (1 in1)

若存在,输出这样的一个数列

简单的线段合并模拟

a1的范围是[l1,r1],那么a2的范围是被包含在[l1-k,ri+k]内的,那么a2的范围就是[l1-k,ri+k]和[l2,r2]的交集,这样再推出a3,a4...an的范围

然后在an选一个数,再确定an-1,再确定an-2...从后往前确定数

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int MAXN = 1e5+7;
struct LINE{
	long long l,r;
}line[MAXN];
long long l, r;
long long ans[MAXN];
bool merge(LINE a,LINE b){
	if(a.r<b.l||a.l>b.r) return false;
	l = max(a.l,b.l);
	r = min(a.r,b.r);
	return true;
}
int main()
{
	int T;
	int n;
	long long k;
	cin>>T;
	while(T--){
		cin>>n>>k;
		for(int i = 1;i <= n;i++){
			scanf("%lld%lld",&line[i].l,&line[i].r);
		}
		bool flag = true;
		LINE pre, aft;
		for(int i = 2;i <= n;i++){
			pre.l = line[i-1].l-k;
			pre.r = line[i-1].r+k;
			if(merge(pre,line[i])){
				line[i].l = l;
				line[i].r = r;
			}
			else {
				flag = false;
				break;
			}
		}
		if(!flag) cout<<"NO"<<endl;
		else{
			cout<<"YES"<<endl;
			ans[n] = line[n].l;
			for(int i = n - 1; i;i--){
				aft.l = ans[i + 1]-k;
				aft.r = ans[i + 1]+k;
				merge(line[i],aft);
				ans[i] = l;
			}
			for(int i = 1;i < n;i++) printf("%lld ",ans[i]);
			printf("%lld\n",ans[n]);
		}
	}
	return 0;
}

  

1008 Hexagon

阴间构造蜂巢题,感觉比第十场的扫雷恶心多了

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std; 
void gon(int n){
	if(n == 1) return;
	if(n == 2) {
		printf("543215");
		return;
	}
	for(int i = 1;i <= n - 2;i++) printf("42");
	printf("3");
	for(int i = 1;i <= n - 2;i++) printf("53");
	printf("4");
	for(int i = 1;i <= n - 2;i++) printf("64");
	printf("5");
	for(int i = 1;i <= n - 2;i++) printf("15");
	printf("6");
	for(int i = 1;i <= n - 2;i++) printf("26");
	printf("1");
	for(int i = 1;i <= n - 3;i++) printf("31");
	printf("2");
	printf("43");
	gon(n-2);
}
int main()
{
	int T, n;
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		gon(n);
		printf("\n");
	}
	return 0;
}

  

1009 Isomorphic Strings

 

哈希

 

加一个小剪枝:总串一共有x种字母,第一段子串有y种字母,x!=y就直接return false;

第一次写双哈希,三哈希

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std; 
const int MAXN = 5e6+7;
const int INF = 1e7;
const int BASE = 29;
const long long MOD1 = 99824435;
const long long MOD2 = 1e9+7; 
//const long long MOD3 = 1e9+9;
char s[MAXN];
int su[26];
long long ten[3][MAXN];
int n;
int kind;
void pre(int n){
	ten[0][0] = ten[1][0] = ten[2][0] = 1;
	for(int i = 1;i <= n;i++){
		ten[0][i] = ten[0][i-1] * 10 % MOD1;
		ten[1][i] = ten[1][i-1] * 10 % MOD2;
		//ten[2][i] = ten[2][i-1] * 10 % MOD3;
	}
}
int gcd(int a,int b){
	if(a<b) swap(a,b);
	while(b){
		a = a % b;
		swap(a,b);
	}
	return a;
}
bool check(int len){
	vector<long long>hash_1,hash_2
	//,hash_3
	;
	bool vis[26]={false};//这里一定要初始化,我这里wa了找了好久qwq
	long long res1 = 0, res2 = 0
	//,res3 = 0
	;
	int kd = 0;
	for(int i = 1;i <= len;i++){
		res1 = res1 * 10 + s[i] - 'a';
		res2 = res2 * 10 + s[i] - 'a';
		//res3 = res3 * 10 + s[i] - 'a';
		res1 %= MOD1;
		res2 %= MOD2;
		//res3 %= MOD3;
		if(!vis[s[i]-'a']){
			kd++;
			vis[s[i]-'a'] = true;
		}
	}
	if(kd!=kind) return false;
	hash_1.push_back(res1);
	hash_2.push_back(res2);
	//hash_3.push_back(res3);
	for(int i = 1;i < len;i++){
		res1 -= (long long)1 * (s[i] - 'a') * ten[0][len-1];
		res1 = (res1 % MOD1 + MOD1) * 10 % MOD1;
		res1 += s[i] - 'a';
		res1 %= MOD1;
		res2 -= (long long)1 * (s[i] - 'a') * ten[1][len-1];
		res2 = (res2 % MOD2 + MOD2) * 10 % MOD2;
		res2 += s[i] - 'a';
		res2 %= MOD2;
		//res3 -= (long long)1 * (s[i] - 'a') * ten[2][len-1];
		//res3 = (res3 % MOD3 + MOD3) * 10 % MOD3;
		//res3 += s[i] - 'a';
		//res3 %= MOD3;
		hash_1.push_back(res1);
		hash_2.push_back(res2);
		//hash_3.push_back(res3); 
	}	 
	for(int pos = 1;pos < n / len;pos++){
		bool flag = false;
		res1 = 0;res2 = 0;
		//res3 = 0;
		int st = pos * len;
		for(int i = 1;i<=len;i++){
			res1 = res1 * 10 + s[st + i] - 'a';
			res1 %= MOD1;
			res2 = res2 * 10 + s[st + i] - 'a';
			res2 %= MOD2; 
			//res3 = res3 * 10 + s[st + i] - 'a';
			//res3 %= MOD3; 
		}
		for(int i = 0;i < hash_1.size();i++){
			if(hash_1[i]==res1&&hash_2[i]==res2
			//&&hash_3[i]==res3
			)
			 {
				flag = true;
				break;
			}
		}
		if(!flag) return false;
	}
	return true;
}
int main()
{
	pre(5e6);
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		getchar();
		kind = 0;
		for(int i = 0;i < 26;i++) su[i] = 0;
		for(int i = 1;i <= n;i++){
			scanf("%c",&s[i]);
			su[s[i]-'a']++;
		} 
		int gg;
		int first;
		int mi = INF;
		for(int i = 0;i < 26;i++) 
			if(su[i]) {
				kind++;
				mi = min(mi,su[i]);
			}	
		for(int i = 0;i < 26;i++){
			if(su[i]) {
				gg = su[i];
				first = i;
				break;
			}
		}
		for(int i = first + 1;i < 26;i++){
			if(su[i]) gg = gcd(gg,su[i]);
		}
		bool flag = false;
		for(int k = 2;k <= gg;k ++){
			if(n%k) continue;
			int len = n / k;
			if(check(len)) {
				flag = true;
				break;
			}
		}
		if(flag) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

  

posted @ 2020-08-29 00:13  beta_dust  阅读(132)  评论(0编辑  收藏  举报