1469: Handles
#include <stdio.h>
#include <string.h>
using namespace std;
char a[1005][1005];
int xx[1005],yy[1005];
int n,m;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
memset(xx,0,sizeof(xx));
memset(yy,0,sizeof(yy));
for(int i=0;i<n;i++)
scanf("%s",a[i]);
int q;
scanf("%d",&q);
while(q--)
{
int x,y;
scanf("%d%d",&x,&y);
a[x-1][y-1]=(a[x-1][y-1]=='+'?'-':'+');
xx[x-1]++;
yy[y-1]++;
}
for(int i=0;i<n;i++)
{
if(xx[i]%2!=0)
{
for(int j=0;j<m;j++)
a[i][j]=(a[i][j]=='+'?'-':'+');
}
}
for(int i=0;i<m;i++)
{
if(yy[i]%2!=0)
{
for(int j=0;j<n;j++)
a[j][i]=(a[j][i]=='+'?'-':'+');
}
}
int sum=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(a[i][j]=='+')
sum++;
printf("%d\n",sum);
}
return 0;
}
#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
const int maxn=105;
int x[maxn],y[maxn];
int n;
double dist(int i,int j)
{
return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])+0.000001);
}
bool judge(int i,int j)
{
int a=y[j]-y[i];
int b=x[i]-x[j];
int c=x[j]*y[i]-x[i]*y[j];
int u=x[i]-x[j];
int d=y[i]-y[j];
int lf=0,rt=0;
if(u==0&&d!=0)
{
for(int k=0; k<n; k++)
{
if(x[k]<x[i])
{
lf++;
}
if(x[k]>x[i])
{
rt++;
}
}
}
else if(d==0&&u!=0)
{
for(int k=0; k<n; k++)
{
if(y[k]<y[i])
{
lf++;
}
if(y[k]>y[i])
{
rt++;
}
}
}
else
{
for(int k=0; k<n; k++)
{
if(a*x[k]+b*y[k]+c>0)
{
lf++;
}
else if(a*x[k]+b*y[k]+c<0)
{
rt++;
}
}
}
if(fabs(rt-lf)<=1) return true;
else return false;
}
int main()
{
while(~scanf("%d",&n)&&n)
{
for(int i=0; i<n; i++)
{
scanf("%d%d",&x[i],&y[i]);
}
double Max=0x3f3f3f3f3f;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(judge(i,j)){
double temp=dist(i,j);
if(temp<Max)
Max=temp;
}
}
}
printf("%.3lf\n",Max);
}
return 0;
}
#include<iostream>
#include<algorithm>
using namespace std;
#include<map>
const int MOD=1e9+7;
typedef long long ll;
map<pair<ll,ll>,int>v;
map<pair<ll,ll>,int>::iterator it;
int gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
int main()
{
ll c;
int cas=0;
while(scanf("%lld",&c)!=EOF&&c)
{
v.clear();
ll m=sqrt(c);
for(ll i=1;i<=m;i++)
{
ll j=sqrt(c-i*i);
if(j*j+i*i!=c||j<=i)continue;
ll x=j*j-i*i;
ll y=2*j*i;
if(x>y)swap(x,y);
if(gcd(x,y)!=1||gcd(x,c)!=1||gcd(c,y)!=1)continue;
if(v[make_pair(x,y)])continue;
v[make_pair(x,y)]=1;
}
if(cas)printf("\n");
printf("Case %d:\n",++cas);
printf("There are %d solution(s).\n",v.size());
for(it=v.begin();it!=v.end();it++)printf("%lld^2 + %lld^2 = %lld^2\n",it->first.first,it->first.second,c);
}
return 0;
}