标签:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cctype>
#define clr(x,y) memset(x, y, sizeof x)
#include <cmath>
using namespace std;
const int maxn=6e2+6;
const int maxm=maxn*maxn*2;
int first[maxn];
struct edge{
int nxt,t,f;
}e[maxm];
void addedge(int f,int t,int ind){
e[ind].nxt=first[f];
e[ind].t=t;
e[ind].f=f;
first[f]=ind;
}
int n;
char maz[maxn][maxn];
bool vis[maxn];
int match[maxn];
bool dfs(int f){
vis[f]=true;
for(int p=first[f];p!=-1;p=e[p].nxt){
int t=e[p].t;
int mch=match[t];
if(mch==-1||(!vis[mch]&&dfs(mch))){
match[t]=f;
match[f]=t;
return true;
}
}
// printf("dfs %d no\n",f);
return false;
}
int findmatch(){
int ans=0;
for(int i=0;i<n;i++){
if(match[i]==-1){
clr(vis,0);
if(dfs(i))ans++;
}
}
return ans;
}
void init(){
clr(first,-1);
clr(match,-1);
}
int main(){
//freopen("input.txt","r",stdin);
while(scanf("%d",&n)==1){
init();
int en=0;
for(int i=0;i<n;i++)scanf("%s",maz[i]);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(maz[i][j]==‘U‘){
addedge(i,j+n,en++);
addedge(j+n,i,en++);
}
}
}
int ans=findmatch();
if(ans==n){
puts("YES");
}
else {
puts("NO");
}
}
return 0;
}
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cctype>
#define clr(x,y) memset(x, y, sizeof x)
#include <cmath>
using namespace std;
const int maxn=2e3+3;
typedef long long ll;
char maz[maxn];
long long read(int& head){
//printf("read start from %d ",head);
long long ans=0;
while(isalnum(maz[head])){
ans*=10;
ans+=maz[head]-‘0‘;
head++;
}
// printf("end at %d ans = %lld\n",head,ans);
return ans;
}
typedef pair<long long ,int > p;
p calc(int st){
long long ans=0;
int cnt=1,ind =st;
for(;maz[ind]!=0&&maz[ind]!=‘]‘;){
if(maz[ind]==‘-‘){
cnt=-1;
ind ++;
//printf("calc ind %d cnt -1\n",ind);
}
else if(maz[ind]==‘+‘){
ind++;
}
else if(isalnum(maz[ind])){
ans+=cnt*read(ind);
cnt=1;
//printf("calc ind %d cnt 1 ans%lld \n",ind,ans);
}
else if(maz[ind]==‘[‘){
ind++;
p tmp=calc(ind);
ans+=cnt*tmp.first;
ind=tmp.second+1;
cnt=1;
}
}
//printf("calc start at %d end at %d ans = %lld\n",st,ind,ans);
return p(ans,ind);
}
int main(){
//freopen("input.txt","r",stdin);
while(scanf("%s",maz)==1){
long long a,b;
scanf("%lld%lld",&a,&b);
if(a==9){
puts("A");
continue;
}
else if(b==9){
puts("B");
continue;
}
long long ans=calc(0).first;
if(ans==a){
puts("B");
}
else puts("A");
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/xuesu/p/4508208.html