ICPC Asia Taipei-Hsinchu Contest
有一说一,正常有点简单。
A.
哈希矩阵然后做bfs。写得过于长了,,然后打的时候忘记了,重载怎么打了,就打了一个手写的hash上去。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<bitset>
#include<map>
//#include<regex>
#include<cstdio>
#include <iomanip>
#include<unordered_map>
#pragma GCC optimize(2)
#define up(i,a,b) for(int i=a;i<b;i++)
#define dw(i,a,b) for(int i=a;i>b;i--)
#define upd(i,a,b) for(int i=a;i<=b;i++)
#define dwd(i,a,b) for(int i=a;i>=b;i--)
//#define local
typedef long long ll;
typedef unsigned long long ull;
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
ll read()
{
char ch = getchar(); ll x = 0, f = 1;
while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * f;
}
typedef pair<int, int> pir;
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lrt root<<1
#define rrt root<<1|1
struct matrix {
int grp[8][8];
void mst()
{
up(i,0,6)up(j,0,6)grp[i][j] = 0;
}
};
struct c {
int x, y1, y2;
int flag;
}car[15];
map<ull, int>mp;
queue<pair<matrix,int> >q;
int grp[10][10];
int dx[2] = { 1,0 };
int dy[2] = { 0,1 };
int vis[11];
vector<pir>vec[15];
ull Hash[40];
ull base = 4000007;
void eq(matrix &a)
{
up(i, 0, 6)
up(j, 0, 6)a.grp[i][j] = grp[i][j];
}
void init_h(matrix a)
{
Hash[0] = 0;
int cnt = 0;
up(i, 0, 6)
{
up(j, 0, 6)
{
cnt++;
Hash[cnt] = Hash[cnt - 1] * base + (a.grp[i][j]+1) * cnt;
}
}
}
void getdir(matrix temp)
{
up(i, 0, 6)up(j, 0, 6)grp[i][j] = temp.grp[i][j];
up(i, 0, 6)
{
up(j, 0, 6)
{
int temp_pos = grp[i][j];
if (grp[i][j])
{
vec[grp[i][j]].push_back(make_pair(i, j));
}
}
}
upd(i, 1, 10)
{
if (vec[i].size())
{
if (vec[i][0].first == vec[i][1].first)
{
car[i].flag = 0;
car[i].x = vec[i][0].first;
for (auto k : vec[i])
{
car[i].y1 = min(car[i].y1, k.second);
car[i].y2 = max(car[i].y2, k.second);
}
}
else {
car[i].flag = 1;
car[i].x = vec[i][0].second;
for (auto k : vec[i])
{
car[i].y1 = min(car[i].y1, k.first);
car[i].y2 = max(car[i].y2, k.first);
}
}
}
}
}
void print(matrix a)
{
up(i, 0, 6)
{
up(j, 0, 6)printf("%d ", a.grp[i][j]); cout << endl;
}
cout << endl;
}
int main()
{
matrix init;
up(i, 0, 6)
{
int cnt = 0;
up(j, 0, 6)
{
init.grp[i][j] = read();
}
}
init_h(init);
mp[Hash[36]] = 1;
q.push(make_pair(init, 0));
getdir(init);
int ans = 15;
while (!q.empty())
{
matrix tt = q.front().first; int val = q.front().second; q.pop();
if (val > 8)continue;
upd(i, 1, 10)vec[i].clear();
upd(i, 0, 10)vis[i] = 0, car[i].x = car[i].y2 = 0, car[i].y1 = car[i].flag = 10;
getdir(tt);
if (car[1].x == 2 && car[1].flag == 0 && car[1].y2 == 5)
{
ans = min(ans, val + 2);
continue;
}
int temp_grp[10][10];
memcpy(temp_grp, grp,sizeof(grp));
upd(i, 1, 10)
{
memcpy(grp, temp_grp, sizeof(temp_grp));
if (vec[i].size())
{
if (car[i].flag == 0)
{
matrix one; one.mst();
eq(one);
//print(one);
upd(j, car[i].y1, car[i].y2)one.grp[car[i].x][j] = 0;
if (car[i].y2 <= 4&&!grp[car[i].x][car[i].y2+1])
{
car[i].y1++; car[i].y2++;
upd(j, car[i].y1, car[i].y2)one.grp[car[i].x][j] = i;
//print(one);
init_h(one);
if (mp[Hash[36]] == 0)
{
mp[Hash[36]] = 1;
q.push(make_pair(one, val + 1));
}
upd(j, car[i].y1, car[i].y2)one.grp[car[i].x][j] = 0;
car[i].y1--; car[i].y2--;
}
if (car[i].y1 >= 1 && !grp[car[i].x][car[i].y1- 1])
{
car[i].y1--; car[i].y2--;
upd(j, car[i].y1, car[i].y2)one.grp[car[i].x][j] = i;
//print(one);
init_h(one);
if (mp[Hash[36]] == 0)
{
mp[Hash[36]] = 1;
q.push(make_pair(one, val + 1));
}
}
}
else {
matrix one; one.mst();
eq(one);
upd(j, car[i].y1, car[i].y2)one.grp[j][car[i].x] = 0;
if (car[i].y2 <= 4 && !grp[car[i].y2+1][car[i].x])
{
car[i].y1++; car[i].y2++;
upd(j, car[i].y1, car[i].y2)one.grp[j][car[i].x] = i;
//print(one);
init_h(one);
if (mp[Hash[36]] == 0)
{
mp[Hash[36]] = 1;
q.push(make_pair(one, val + 1));
}
upd(j, car[i].y1, car[i].y2)one.grp[j][car[i].x] = 0;
car[i].y1--; car[i].y2--;
}
if (car[i].y1 >= 1 && !grp[car[i].y1 - 1][car[i].x])
{
car[i].y1--; car[i].y2--;
upd(j, car[i].y1, car[i].y2)one.grp[j][car[i].x] = i;
//print(one);
init_h(one);
if (mp[Hash[36]] == 0)
{
mp[Hash[36]] = 1;
q.push(make_pair(one, val + 1));
}
}
}
}
}
}
if (ans == 15)
cout << -1 << endl;
else cout << ans << endl;
return 0;
}
C.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vi vector<int>
#define vl vector<vll>
#define pii pair<int,int>
#define pll pair<ll>
inline bool isprime(ll num)
{if(num==2||num==3)return true;
if(num%6!=1&&num%6!=5)return false;
for(int i=5;1ll*i*i<=num;i+=6){if(num%i==0||num%(i+2)==0)return false;}
return true;}
const int mod = 1e9+7;
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll g = exgcd(b,a%b,y,x);y-=a/b*x;return g;}
inline ll quick_pow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res=mul(res,a,mod);a=mul(a,a,mod);b>>=1;}return res;}
inline ll quick_pow(ll a,ll b){ll res=1;while(b){if(b&1)res=mul(res,a,mod);a=mul(a,a,mod);b>>=1;}return res;}
inline ll inv(ll x){return quick_pow(x,mod-2);}
inline ll inv(ll x,ll mod){return quick_pow(x,mod-2,mod);}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int N = 100;
int a[N];
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)scanf("%d",&a[i]);
bool flag = true;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
for(int k=0;k<n;k++){
if(k==i||k==j)continue;
if(abs(a[i]-a[j])%a[k]!=0)flag=false;
}
}
}
if(flag)printf("yes\n");
else printf("no\n");
}
D.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vi vector<int>
#define vl vector<vll>
#define pii pair<int,int>
#define pll pair<ll>
inline bool isprime(ll num)
{if(num==2||num==3)return true;
if(num%6!=1&&num%6!=5)return false;
for(int i=5;1ll*i*i<=num;i+=6){if(num%i==0||num%(i+2)==0)return false;}
return true;}
const int mod = 1e9+7;
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll g = exgcd(b,a%b,y,x);y-=a/b*x;return g;}
inline ll quick_pow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res=mul(res,a,mod);a=mul(a,a,mod);b>>=1;}return res;}
inline ll quick_pow(ll a,ll b){ll res=1;while(b){if(b&1)res=mul(res,a,mod);a=mul(a,a,mod);b>>=1;}return res;}
inline ll inv(ll x){return quick_pow(x,mod-2);}
inline ll inv(ll x,ll mod){return quick_pow(x,mod-2,mod);}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int main(){
string s;
bool flag = true;
for(int i=0;i<3;i++){
cin>>s;
if(s!="bubble"&&s!="tapioka")cout<<s<<" ",flag=false;
}
if(flag)cout<<"nothing";
}
E.
观察到了,实际的算法就是,正负断开,然后观察得到,当距离足够长的时候,对于1e9的差值来说,一定能沟通过构造正负有别来实现。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<bitset>
#include<map>
//#include<regex>
#include<cstdio>
#include <iomanip>
#pragma GCC optimize(2)
#define up(i,a,b) for(int i=a;i<b;i++)
#define dw(i,a,b) for(int i=a;i>b;i--)
#define upd(i,a,b) for(int i=a;i<=b;i++)
#define dwd(i,a,b) for(int i=a;i>=b;i--)
//#define local
typedef long long ll;
typedef unsigned long long ull;
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
ll read()
{
char ch = getchar(); ll x = 0, f = 1;
while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * f;
}
typedef pair<int, int> pir;
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lrt root<<1
#define rrt root<<1|1
const int N = 2e3 + 10;
int T, k, L;
int ans[N];
int main()
{
T = read();
while (T--)
{
k = read(); L = read();
if (L > 2000)
{
printf("-1\n");
continue;
}
else {
int sum = k + max(L,2) - 1;
sum++;
ans[1] = -1;
upd(i, 2, max(L, 2))
{
ans[i] = min((int)1e6, sum);
sum -= ans[i];
}
printf("%d\n", max(L, 2));
upd(i, 1, max(L, 2))
{
printf("%d ", ans[i]);
}
printf("\n");
}
}
return 0;
}
H.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vi vector<int>
#define vl vector<vll>
#define pii pair<int,int>
#define pll pair<ll>
inline bool isprime(ll num)
{if(num==2||num==3)return true;
if(num%6!=1&&num%6!=5)return false;
for(int i=5;1ll*i*i<=num;i+=6){if(num%i==0||num%(i+2)==0)return false;}
return true;}
const int mod = 1e9+7;
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll g = exgcd(b,a%b,y,x);y-=a/b*x;return g;}
inline ll quick_pow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res=mul(res,a,mod);a=mul(a,a,mod);b>>=1;}return res;}
inline ll quick_pow(ll a,ll b){ll res=1;while(b){if(b&1)res=mul(res,a,mod);a=mul(a,a,mod);b>>=1;}return res;}
inline ll inv(ll x){return quick_pow(x,mod-2);}
inline ll inv(ll x,ll mod){return quick_pow(x,mod-2,mod);}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
int x;
scanf("%d",&x);
printf("%lld\n",(1ll*x*(x+1))^(x+1));
}
}
L.
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#define ll long long
using namespace std;
int const N=5020;
int n,m,t,Q;
struct P{
ll x,y;
int id;
bool operator ==(const P& b) const {
return (id == b.id) ;
}
};
P a[N],f[N];
ll dis(P a,P b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
ll cross(P a,P b,P c){
ll x1=a.x-c.x,x2=a.x-b.x,y1=a.y-c.y,y2=a.y-b.y;
return x1*y2-x2*y1;
}
int cmp(P &a1,P &b1){
ll temp=cross(a1,b1,a[1]);
if (temp<0) return 0;
if (temp==0 && dis(a[1],a1)>dis(a[1],b1)) return 0;
return 1;
}
int main(){
scanf("%d",&Q);
while (Q--){
ll ans=0;
ll temp1,temp2;
scanf("%d",&n);
for (int i=1;i<=n;i++){
scanf("%lld%lld",&a[i].x,&a[i].y);
a[i].id=i;
if(a[i].y<a[1].y ||(a[i].y==a[1].y && a[i].x<a[1].x))
{
P t=a[1];a[1]=a[i];a[i]=t;
}
}
sort(a+2,a+1+n,cmp);
int t=0;
a[++n]=a[1];
for (int i=1;i<n;i++){
while (t>1 && cross(f[t],a[i],f[t-1])<=0) t--;
f[++t]=a[i];
}
if (t<3) printf("0\n");
else if (t==3){
ll size=abs(cross(f[1],f[2],f[3]));
for (int i=1;i<n;i++){
if (a[i]==f[1] || a[i]==f[2] || a[i]==f[3]) continue;
ll minx=min(abs(cross(a[i],f[2],f[3])),min(abs(cross(f[1],a[i],f[3])),abs(cross(f[1],f[2],a[i]))));
ans=max(ans,size-minx);
}
if(ans%2!=0) printf("%lld.5\n",ans/2);
else printf("%lld\n",ans/2);
}
else{
for (int i=1;i<t;i++){
int k=i+3,p=i+1;
for (int j=i+2;j<t;j++){
while (k<t && abs(cross(f[i],f[j],f[k]))<abs(cross(f[i],f[j],f[k+1]))) k++;
while (p<j-2 && abs(cross(f[i],f[p],f[j]))<abs(cross(f[i],f[p+1],f[j]))) p++;
temp1=abs(cross(f[i],f[j],f[k]));
temp2=abs(cross(f[i],f[p],f[j]));
ans=max(ans,temp1+temp2);
}
}
if(ans%2!=0) printf("%lld.5\n",ans/2);
else printf("%lld\n",ans/2);
}
}
return 0;
}
橙橙橙