QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#289368#7862. Land Tradeucup-team266#Compile Error//C++205.3kb2023-12-23 17:19:162023-12-23 17:19:16

Judging History

你现在查看的是最新测评结果

  • [2023-12-23 17:19:16]
  • 评测
  • [2023-12-23 17:19:16]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
#define x first
#define y second
void die(string S){puts(S.c_str());exit(0);}
const double eps=1e-8;
struct line
{
	double A,B,C;
	line(double _A,double _B,double _C):A(_A),B(_B),C(_C){}
	line(){}
}L[1010];
int x1,x2,y1,y2;
string s;
struct formula
{
	formula *a,*b;
	int op;
};
const pair<double,double> error=mp(20210109,20210448);
pair<double,double> its(line a,line b)
{
	double B=a.B*b.A-b.B*a.A,C=a.C*b.A-b.C*a.A;
	double y=-C/B;
	double x=(-a.C-a.B*y)/a.A;
	if(isnan(y)||y<-1e9||y>1e9) return error;
	if(isnan(x)) x=(-b.C-b.B*y)/b.A;
	return mp(x,y);
}
int tot;
formula *get(int l,int r)
{
//	cerr<<l<<" "<<r<<endl;
	int c=0,p=-1;
	for(int i=l;i<=r;i++)
	{
		if(s[i]=='(')
			c++;
		if(s[i]==')')
			c--;
		if(s[i]=='!'||s[i]=='&'||s[i]=='|'||s[i]=='^') if(!c)
			p=i;
	}
	if(p==-1)
	{
		if(s[l]=='(')
			return get(l+1,r);
		formula *ret=new formula;
		ret->op=++tot;
		vector<int> vec;
		int x=0,f=0;
		for(int i=l;i<=r;i++)
		{
			if(isdigit(s[i]))
			{
				x=x*10+(s[i]^48);
				if(!f) f=1;
			}
			else if(s[i]=='-')
				f=-1;
			else if(f)
			{
				vec.pb(x*f);
				x=0;
				f=0;
			}
		}
		L[tot]=line(vec[0],vec[1],vec[2]);
		return ret;
	}
	else
	{
		if(s[p]=='!')
		{
			formula *ret=new formula;
			ret->op=-4;
			ret->a=get(l+1,r);
			return ret;
		}
		formula *ret=new formula;
		ret->op=(s[p]=='&'?-1:(s[p]=='|'?-2:-3));
		ret->a=get(l,p-1);
		ret->b=get(p+1,r);
		return ret;
	}
}
vector<pair<pair<double,double>,pii>> vec;
int lst[1010];
vector<pair<double,int>> G[100100];
double calc(int a,int b)
{
	return atan2(vec[b].x.y-vec[a].x.y,vec[b].x.x-vec[a].x.x);
}
map<int,int> index[100100];
map<pii,bool> vis;
bool status[100100];
pair<double,double> ctr(pair<double,double> a,pair<double,double> b,pair<double,double> c)
{
	return mp((a.x+b.x+c.x)/3,(a.y+b.y+c.y)/3);
}
bool calc(formula *F)
{
	if(F->op>0) return status[F->op];
	if(F->op==-4) return !calc(F->a);
	bool a=calc(F->a),b=calc(F->b);
	if(F->op==-1) return a&b;
	if(F->op==-2) return a|b;
	return a^b;
}
map<pair<double,double>,vector<int>> belong;
const bool operator ==(const pair<double,double> &a,const pair<double,double> &b)
{
	return fabs(a.x-b.x)<eps&&fabs(a.y-b.y)<eps;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>x1>>x2>>y1>>y2;
	cin>>s;
	formula *F=get(0,sz(s)-1);
	L[tot+1]=line(1,0,-x1);
	L[tot+2]=line(0,-1,y2);
	L[tot+3]=line(-1,0,x2);
	L[tot+4]=line(0,1,-y1);
	int cnt=0;
	for(int i=1;i<=tot+4;i++)
		for(int j=i+1;j<=tot+4;j++)
		{
			pair<double,double> p=its(L[i],L[j]);
			if(p==error) continue;
//			cerr<<i<<" "<<j<<" "<<p.x<<" "<<p.y<<endl;
			if(p.x<x1-eps||p.x>x2+eps||p.y<y1-eps||p.y>y2+eps)
				continue;
			belong[p].pb(i);
			belong[p].pb(j);
			vec.pb(p,mp(0,0));
		}
	srt(vec);
	uni(vec);
	int n=sz(vec);
	memset(lst,-1,sizeof(lst));
	for(int i=0;i<n;i++)
	{
		auto pr=vec[i];
		bool flag=0;
		srt(belong[pr.first]);
		uni(belong[pr.first]);
		for(auto a:belong[pr.first])
		{
			if(a>tot) flag=1;
			if(lst[a]!=-1)
			{
				G[lst[a]].pb(calc(lst[a],i),i);
				G[i].pb(calc(i,lst[a]),lst[a]);
			}
			lst[a]=i;
		}
		cnt+=flag;
	}
//	cerr<<cnt<<endl;
	for(int i=0;i<n;i++)
	{
		srt(G[i]);
		for(int j=0;j<sz(G[i]);j++)
			index[i][G[i][j].second]=j;
	}
	vector<array<int,3>> pool;
	for(int i=0;i<n;i++)
		for(auto pr:G[i])
			if(!vis[mp(i,pr.second)])
			{
				vector<int> cvh;
				int cura=i,curb=pr.second;
				while(!vis[mp(cura,curb)])
				{
					vis[mp(cura,curb)]=1;
					cvh.pb(curb);
					int p=index[curb][cura];
					p=(p+1)%sz(G[curb]);
					cura=curb;
					curb=G[cura][p].second;
				}
				if(sz(cvh)<3) continue;
				if(sz(cvh)==cnt) continue;
//				for(auto a:cvh)
//					cerr<<a<<" ";
//				cerr<<endl;
//				for(auto a:cvh)
//					cerr<<"("<<vec[a].x.x<<","<<vec[a].x.y<<") ";
//				cerr<<endl;
				for(int i=2;i<sz(cvh);i++)
					pool.push_back({cvh[0],cvh[i-1],cvh[i]});
			}
//	cerr<<F->op<<endl;
	double ans=0;
	for(auto arr:pool)
	{
		int a=arr[0],b=arr[1],c=arr[2];
		pair<double,double> center=ctr(vec[a].first,vec[b].first,vec[c].first);
		memset(status,0,sizeof(status));
		for(int i=1;i<=tot;i++)
			if(L[i].A*center.x+L[i].B*center.y+L[i].C>-eps)
				status[i]=1;
		if(calc(F))
		{
			double S=0;
			double ax=vec[a].x.x-vec[c].x.x,ay=vec[a].x.y-vec[c].x.y,bx=vec[b].x.x-vec[c].x.x,by=vec[b].x.y-vec[c].x.y;
			S=fabs(ax*by-ay*bx)/2;
//			cerr<<vec[a].x.x<<" "<<vec[a].x.y<<" "<<vec[b].x.x<<" "<<vec[b].x.y<<" "<<vec[c].x.x<<" "<<vec[c].x.y<<endl;
//			cerr<<status[1]<<" "<<status[2]<<" "<<status[3]<<" "<<status[4]<<" "<<calc(F)<<endl;
//			cerr<<S<<endl;
			ans+=S;
		}
	}
	printf("%.20lf\n",ans);
	return 0;
}

详细

answer.code:31:11: error: ‘int y1’ redeclared as different kind of entity
   31 | int x1,x2,y1,y2;
      |           ^~
In file included from /usr/include/features.h:461,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/c++config.h:586,
                 from /usr/include/c++/11/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:33,
                 from answer.code:2:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:221:1: note: previous declaration ‘double y1(double)’
  221 | __MATHCALL (y1,, (_Mdouble_));
      | ^~~~~~~~~~
answer.code:112:26: error: ‘std::map<int, int> index [100100]’ redeclared as different kind of entity
  112 | map<int,int> index[100100];
      |                          ^
In file included from /usr/include/string.h:432,
                 from /usr/include/c++/11/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:48,
                 from answer.code:2:
/usr/include/strings.h:61:1: note: previous declaration ‘const char* index(const char*, int)’
   61 | index (const char *__s, int __c) __THROW
      | ^~~~~
answer.code: In function ‘int main()’:
answer.code:138:20: error: no match for ‘operator>>’ (operand types are ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} and ‘double(double) noexcept’)
  138 |         cin>>x1>>x2>>y1>>y2;
      |         ~~~~~~~~~~~^~~~
      |                |     |
      |                |     double(double) noexcept
      |                std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:2:
/usr/include/c++/11/istream:120:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__istream_type& (*)(std::basic_istream<_CharT, _Traits>::__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ (near match)
  120 |       operator>>(__istream_type& (*__pf)(__istream_type&))
      |       ^~~~~~~~
/usr/include/c++/11/istream:120:7: note:   conversion of argument 1 would be ill-formed:
answer.code:138:22: error: invalid conversion from ‘double (*)(double) noexcept’ to ‘std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&)’ {aka ‘std::basic_istream<char>& (*)(std::basic_istream<char>&)’} [-fpermissive]
  138 |         cin>>x1>>x2>>y1>>y2;
      |                      ^~
      |                      |
      |                      double (*)(double) noexcept
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:2:
/usr/include/c++/11/istream:124:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__ios_type& (*)(std::basic_istream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>; std::basic_istream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]’ (near match)
  124 |       operator>>(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/11/istream:124:7: note:   conversion of argument 1 would be ill-formed:
answer.code:138:22: error: invalid conversion from ‘double (*)(double) noexcept’ to ‘std::basic_istream<char>::__ios_type& (*)(std::basic_istream<char>::__ios_type&)’ {aka ‘std::basic_ios<char>& (*)(std::basic_ios<char>&)’} [-fpermissive]
  138 |         cin>>x1>>x2>>y1>>y2;
      |                      ^~
      |                      |
      |                      double (*)(double) noexcept
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:2:
/usr/include/c++/11/istream:131:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ (near match)
  131 |       operator>>(ios_base& (*__pf)(ios_base&))
      |       ^~~~~~~~
/usr/include/c++/11/istream...