锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
#include<queue>
#include<cmath>
using namespace std;
struct NODE
{
int p_x,p_y,step,c_x,c_y,d;
};
queue<NODE> que;
const int MAXN = 100;
bool p[MAXN][MAXN][4],c[MAXN][MAXN];
int map[MAXN][MAXN];
int mv[4][2]={-1,0,0,1,1,0,0,-1},p_sm,p_sn,c_sm,c_sn,m,n;
void init ( )
{
memset(p,false,sizeof(p));
for ( int i=0 ; i<m ; i++ )
for ( int j=0 ; j<n ; j++ )
{
scanf("%d",&map[i][j]);
if ( map[i][j]==4 )
p_sm=i,p_sn=j;
else
if ( map[i][j]==2 )
c_sm=i,c_sn=j;
}
}
int bfs ( )
{
NODE temp,go;
int i;
temp.p_x = p_sm;
temp.p_y = p_sn;
temp.c_x = c_sm;
temp.c_y = c_sn;
temp.step = 0;
temp.d=0;
for ( i=0 ; i<4 ; i++ )
{
p[p_sm][p_sn][i]=true;
temp.d=i;
que.push(temp);
}
c[c_sm][c_sn]=true;
while ( !que.empty () )
{
NODE head=que.front();
que.pop() ;
for ( i=0 ; i<4 ; i++ )
{
int tm=head.p_x+mv[i][0] , tn=head.p_y+mv[i][1] ;
if ( tm>=0 && tm<m && tn>=0 && tn<n && !p[tm][tn][i] && i!=(head.d+2)%4 && map[tm][tn]!=1 )
{
double t=sqrt( (double)( (tm-head.c_x)*(tm-head.c_x) ) +(double)( (tn-head.c_y)*(tn-head.c_y) ));
if ( t <= sqrt(2.0) && t>0 )
{
go=head;
go.p_x = tm;
go.p_y = tn;
go.step ++ ;
go.d=i;
p[tm][tn][i]=true;
que.push(go);
}
else
{
int tmm=tm+mv[i][0] , tnn=tn+mv[i][1];
if ( t==0 && tmm>=0 && tmm<m && tnn>=0 && tnn<n && map[tmm][tnn]!=1 && !c[tmm][tnn] )
{
go.c_x = tmm ;
go.c_y = tnn ;
go.p_x = tm;
go.d=i;
go.p_y = tn;
go.step = head.step+1;
if ( map[tmm][tnn]==3 )
return go.step ;
c[tmm][tnn]=true;
p[tm][tn][i]=true;
que.push(go);
}
}
}
}
}
return -1;
}
int main ( )
{
while ( scanf("%d%d",&n,&m)!=EOF )
{
init();
printf("%d\n",bfs());
// que.
}
}
#include"cqueue.h"
#include<iostream>
void char_queue::enqueue(char d)
{
if ( tail>=max )
throw ( bad_op( ) );
else
c[tail++]=d;
}
char char_queue::dequeue()
{
return c[head++];
}
int char_queue::isEmpty()
{
return head==tail?1:0;
}
#include<cstdio>
class char_queue
{
int head,tail,max;
char c[10000];
public:
char_queue() {head=0; tail=0; max=10000; }
void enqueue( char );
char dequeue( );
int isEmpty();
class bad_op
{
public :
int type ;
bad_op( ) { type=1 ; }
};
};
#include<iostream>
#include<sstream>
#include<map>
#include<string>
#include<vector>
#include<iomanip>
#include<fstream>
using namespace std;
typedef map< string , vector<int> > WORD;
void init ( WORD & m )
{
ifstream fin;
fin.open("keywords.txt");
string keyword;
while ( fin>>keyword )
m[keyword];
fin.close();
}
void count ( WORD & m )
{
int line=0;
ifstream fin;
fin.open("text.txt");
string str;
while ( getline(fin,str) )
{
stringstream SS(str);
line++;
while(SS>>str)
{
if ( m.find(str)!=m.end() )
m[str].push_back (line);
}
}
fin.close();
}
void output ( WORD m )
{
string keyword;
for ( WORD::iterator iter_map=m.begin() ; iter_map!=m.end() ; iter_map++ )
{
cout<<setw(10)<<iter_map->first<<":"
<<"(";
for ( vector<int>::iterator iter_vector=iter_map->second.begin() ; iter_vector!=iter_map->second.end(); iter_vector++ )
{
if ( iter_vector!=iter_map->second.begin() )
cout<<",";
cout<<*iter_vector;
}
cout<<")"<<endl;
}
}
int main ()
{
WORD m;
init(m);
count(m);
output(m);
}
#include<iostream>
#include<sstream>
#include<map>
#include<string>
#include<vector>
#include<iomanip>
#include<fstream>
#include<algorithm>
using namespace std;
typedef map< string , vector<int> > WORD;
void init ( WORD & m )
{
ifstream fin;
fin.open("keywords.txt");
string keyword;
while ( fin>>keyword )
m[keyword];
fin.close();
}
void count ( WORD & m )
{
int line=0;
ifstream fin;
fin.open("text.txt");
string str;
while ( getline(fin,str) )
{
line++;
for ( WORD::iterator iter = m.begin () ; iter!=m.end( ); iter++ )
if ( str.find ( iter->first )!=string::npos )
m[iter->first].push_back(line);
}
fin.close();
}
void only( WORD &m )
{
for ( WORD::iterator i=m.begin() ; i!=m.end(); i++ )
{
vector<int>::iterator new_end=unique(i->second.begin(),i->second.end());
i->second.erase(new_end,i->second.end());
}
}
void sort_list ( WORD m , map<int,string> &mm )
{
for ( WORD::iterator iter_m = m.begin() ; iter_m != m.end() ; iter_m++ )
mm[iter_m->second .size ()]=iter_m->first;
}
void output ( WORD m , map<int,string> mm )
{
string keyword;
for ( map<int,string>::reverse_iterator iter=mm.rbegin() ; iter!=mm.rend() ; iter++ )
{
cout<<setw(10)<<iter->second<<":"
<<"(";
for ( vector<int>::iterator iter_vector=m[iter->second].begin() ; iter_vector!=m[iter->second].end(); iter_vector++ )
{
if ( iter_vector!=m[iter->second].begin() )
cout<<",";
cout<<*iter_vector;
}
cout<<")"<<endl;
}
}
int main ()
{
WORD m;
map<int , string> mm;
init(m);
count(m);
sort_list(m,mm);
only(m);
output(m,mm);
}

Description
Instant run-off voting is a system for selecting the most preferred candidate in an election. At the beginning of the process, each voter ranks the candidates from most preferred to least preferred. A series of automated voting rounds are then held to determine the overall winner.
In each round, each voter casts a single vote for his most preferred remaining candidate. If a candidate receives strictly more than 50% of the votes cast in that round, that candidate is declared the winner of the election. Otherwise, the candidate with the fewest votes in that round is eliminated, and another round is held. If multiple candidates are tied for the least number of votes, they are all eliminated. If all the candidates are eliminated, the election ends without a winner.
You are given the preferences of the voters in an election, and you must determine the outcome. There are M candidates numbered 0 to M-1, inclusive. The preferences are given in N lines, where each element describes the preferences of a single voter. This is a permutation of the digits 0 to M-1 in decreasing order of preference. In other words, the first digit is the voter's most preferred candidate, the second digit is his second most preferred candidate, and so on.
Input
There are several test cases,each test case begins with a integer N(1<=N<=50),means there are N voters.The next N lines,each contains a string with the same lenth M(1<=M<=10).Each element of a voter will be a permutation of the digits between 0 and M-1. There is a blank line between each test case.
Output
For each test case,output the number of the candidate who wins the election, or -1 if the election ends without a winner.
Sample Input
5
120
102
210
021
012
8
3120
3012
1032
3120
2031
2103
1230
1230
Sample Output
1
-1
Hint:
Case 1:
Nobody gets an absolute majority in the first round and candidate 2 is eliminated. Candidate 1 then receives 3 votes in the next round, giving an absolute majority.
Case 2:
Candidate 0 is eliminated in the first round of voting. Candidate 2 is eliminated in the second round. In the third round, candidates 1 and 3 get 4 votes each. Neither candidate receives an absolute majority, and they are both eliminated for having the least number of votes, so the election ends without a winner.
榪欓鐨勬姇紲紝姣忚疆閮芥槸浠庣涓涓暟寮濮嬫壘鐨勶紝鎵懼埌絎竴涓病鏈夎娣樻卑鐨勪漢銆?br>鎴戜竴寮濮嬩互涓轟箣鍓嶅嚑杞夌殑浜猴紝鍦ㄥ悗闈笉鑳借閫変簡(jiǎn)銆傘傘傘?
#include<iostream>
#include<string>
#include<iomanip>
#include<vector>
#include<algorithm>
const int MAXN=100;
using namespace std;
int cmp ( const void* p1 , const void *p2 )
{
return *( double* )p1>*(double*)p2?1:-1;
}
typedef struct COLOR
{
string col;
double mean,median,sum,value[MAXN];
int num,p;
}COL;
int find ( vector<COL> &str , COL s )
{
for ( vector<COL>::size_type i = 0; i != str.size(); i++ )
if ( str[i].col==s.col )
{
str[i].sum+=s.sum;
str[i].num++;
str[i].value[str[i].p++]=s.sum;
return 1;
}
return 0;
}
void add ( vector<COL>& str , COL s )
{
if ( !find ( str , s ) )
{
s.p=1;
s.num=1;
s.value[0]=s.sum;
str.push_back(s);
}
}
void output ( vector<COL> str )
{
double s=0,v[MAXN],median;
int n=0,q,j=0;
for (vector<COL>::size_type i = 0; i != str.size(); ++i )
{
for (q=0 ; q<str[i].p ; q++)
v[j++]=str[i].value[q];
s+=str[i].sum;
n+=str[i].p;
qsort(str[i].value,str[i].num,sizeof(str[i].value[0]),cmp);
if (str[i].num%2)
str[i].median=str[i].value[(str[i].num-1)/2];
else
str[i].median=(str[i].value[str[i].num/2]+str[i].value[str[i].num/2-1])/2;
cout<<str[i].col<<"\t"<<": "<<"sum="<<"\t"
<<setw(10)<<str[i].sum<<"\t"<<"mean="<<"\t"
<<setw(10)<<str[i].sum/str[i].num<<"\t"<<"median="<<"\t"
<<setw(10)<<str[i].median<<endl;
/*
for ( int j=0 ; j<str[i].p ; j++ )
cout<<str[i].value[j]<<endl;
*/
}
qsort(v,j,sizeof(v[0]),cmp);
if (n%2!=0)
median=v[(n-1)/2];
else
median=(v[n/2]+v[n/2-1])/2;
cout<<"============================================================================"<<endl;
cout<<"ALL"<<"\t"<<": "<<"sum="<<"\t"
<<setw(10)<<s<<"\t"<<"mean="<<"\t"
<<setw(10)<<s/n<<"\t"<<"median="<<"\t"
<<setw(10)<<median<<endl;
/*
for ( j=0 ; j<n ;j++ )
cout<<v[j]<<endl;
*/
}
int main ( )
{
vector<COL> str;
COL s;
while ( cin>>s.col>>s.sum )
{
add(str,s);
}
output( str );
}
#include<iostream>
#include<fstream>
#include<cstring>
#include<cctype>
using namespace std;
const int MAXN=100000;
int main ( int argc , char *args[] )
{
char p,code;
int i=0,l;
char key[MAXN];
if ( argc<2 )
while ( cin.get(p) && !cin.eof() )
cout.put(p);
else
{
strcpy(key,args[1]);
l=strlen(key);
while ( cin.get(p) && !cin.eof() )
{
if ( p=='\n' )
cout<<'\n';
else
{
code=p^key[i%l];
if ( isprint(code) )
cout<<code;
else
cout<<p;
}
i++;
}
}
}
#include<iostream>
#include<cstring>
using namespace std;
const int MAXN=100000;
int main ( int argc , char *args[] )
{
char p,code;
int i=0,l;
char key[MAXN];
if ( argc<2 )
while ( cin.get(p) )
cout.put(p);
else
{
strcpy(key,args[1]);
l=strlen(key);
while ( cin.get(p) )
{
code=p^key[i%l];
if ( code==26 )
code=27;
cout<<code;
i++;
}
}
}Jerry Huang 鑷?鎴?
鏄劇ず璇︾粏淇℃伅 3鏈?1鏃?(6澶╁墠)
Hi,
鎴戠紪璇戜簡(jiǎn)浣犱滑鐨勪唬鐮侊紝榪涜浜?jiǎn)娴嬭瘯锛屽ソ鍍忓拰甯屾湜鐨劸l撴灉宸窛姣旇緝澶э紝璇蜂綘浠啀媯(gè)鏌ョ‘璁や竴涓嬨?/p>
濡傛灉鏄彁浜ら敊浜?jiǎn)锛岃閲嶆柊鎻愪氦銆?/p>
Thanks
huang
緇撴灉鎴戝彧鎵撲簡(jiǎn)70鍒嗐傘傘傘傘?/p>
#include<iostream>
using namespace std;
/* 鍒ゆ柇瀛楃涓叉槸鍚﹀湪寮曞彿閲岄潰 */
int qutation ( char c , bool &f ,bool f1 )
{
char temp;
if ( c=='"' && f1==false)
{
f=true;
cout<<c;
while ( f==true )
{
cin.get(temp);
if ( temp=='"')
f=false;
cout<<temp;
}
return 1; //鍙戠幇寮曞彿
}
return 0; //娌℃湁鍙戠幇寮曞彿
}
void cut_add ( )
{
char c,temp;
bool f1,f2,f3;
f1=f2=f3=false; // f1鏍囪block娉ㄩ噴,f2鏍囪寮曞彿,f3鏍囪l(fā)ine娉ㄩ噴
while ( cin.get(c) )
{
if ( !qutation(c,f2,f1) ) // 娌℃湁鍑虹幇寮曞彿
{
/*鍒ゆ柇娉ㄩ噴寮澶?/span>*/
if ( c=='/' )
{
cin.get(temp);
if ( temp=='*' )
f1=true;//鎵懼埌浜?jiǎn)block娉ㄩ噴鐨勫紑澶?br>37
else
if ( temp=='/' )
f3=true;//鎵懼埌浜?jiǎn)line娉ㄩ噴鐨勫紑澶?br>40
/*褰撴病鏈夋壘鍒版敞閲婄殑寮澶存椂錛屾墽琛宔lse閮ㄥ垎*/
else
{
cout<<c;
cin.putback(temp);
}
}
else
if ( f1==false && f3==false )
cout<<c;
/*鍒ゆ柇娉ㄩ噴緇撳熬*/
if ( c=='*' )
{
cin.get(temp);
if ( temp=='/' )
f1=false; //鍏抽棴block娉ㄩ噴
else
{
cout<<c;
cin.putback(temp);
}
}
else
if ( c=='\n' )
{
f3=false; //鍏抽棴line娉ㄩ噴
cout<<c;
}
}
}
}
int main ( )
{
cut_add();
}