XVII Open Cup named after E.V. Pankratiev. XXI Ural Championship G glassese of solutions
2017-10-06 22:36
423 查看
折半搜索
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std ;
typedef long long ll ;
typedef pair<ll , ll> p2 ;
map<ll , ll> m ;
map<ll , ll> m2 ;
ll save[60][10] ;
ll n , a , b , x , y ;
void dfs(){
ll i ;
for(ll num = 1 ; num < (1<<(n/2)) ; num ++ ){
ll temp = num ;
i = 0 ;ll a1 = 0 , b1 = 0 ;
while( temp ){
if(temp & 1) a1 += save[i][0] , b1 += save[i][1] ;
temp = temp >> 1 ;
i ++ ;
}
a1 = b * a1 - a * b1 ;
m[a1] ++ ;
}
}
void dfs2(){
ll i ;
for(ll num = 1 ; num < (1<<(n - n/2)) ; num ++ ){
ll temp = num ;
i = n/2 ;ll a1 = 0 , b1 = 0 ;
while( temp ){
if(temp & 1) a1 += save[i][0] , b1 += save[i][1] ;
temp = temp >> 1 ;
i ++ ;
}
a1 = b * a1 - a * b1 ;
//cout << a1 << endl ;
m2[a1] ++ ;
//cout << temp << endl ;
//cout << num << endl ;
}
}
long long pow(int n){
long long ans =1 ;
for(int i = 1 ; i <= n ; i ++ )
ans *= (long long)2 ;
return ans ;
}
int main(){
while(~ scanf("%lld %lld %lld" , &n , &a , &b)){
memset(save , 0 , sizeof(save)) ;
for(ll i = 0 ; i < n ; i ++ ){
scanf("%lld %lld" , &save[i][0] , &save[i][1]) ;
}
ll ans = 0 ;
if( a != 0){
m.clear() , m2.clear() ;
dfs() ; dfs2() ;
map<ll , ll> :: iterator it ;
it = m2.begin() ;
ans += m[0] + m2[0] ; //+ m[0] * m2[0] ;
while(it != m2.end()) {
ll a = it->first ;
ll b = it->second ;
ans += m[-a] * b ;
it ++ ;
}
}else{
ll temp = 0 ;
for(ll i = 0 ; i < n ; i ++ ) if(!save[i][0]) temp ++ ;
ans = (1LL<<temp) - 1 ;
///ans = pow(temp) - 1; also fine
}
printf("%lld\n" , ans ) ;
}
return 0 ;
}
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std ;
typedef long long ll ;
typedef pair<ll , ll> p2 ;
map<ll , ll> m ;
map<ll , ll> m2 ;
ll save[60][10] ;
ll n , a , b , x , y ;
void dfs(){
ll i ;
for(ll num = 1 ; num < (1<<(n/2)) ; num ++ ){
ll temp = num ;
i = 0 ;ll a1 = 0 , b1 = 0 ;
while( temp ){
if(temp & 1) a1 += save[i][0] , b1 += save[i][1] ;
temp = temp >> 1 ;
i ++ ;
}
a1 = b * a1 - a * b1 ;
m[a1] ++ ;
}
}
void dfs2(){
ll i ;
for(ll num = 1 ; num < (1<<(n - n/2)) ; num ++ ){
ll temp = num ;
i = n/2 ;ll a1 = 0 , b1 = 0 ;
while( temp ){
if(temp & 1) a1 += save[i][0] , b1 += save[i][1] ;
temp = temp >> 1 ;
i ++ ;
}
a1 = b * a1 - a * b1 ;
//cout << a1 << endl ;
m2[a1] ++ ;
//cout << temp << endl ;
//cout << num << endl ;
}
}
long long pow(int n){
long long ans =1 ;
for(int i = 1 ; i <= n ; i ++ )
ans *= (long long)2 ;
return ans ;
}
int main(){
while(~ scanf("%lld %lld %lld" , &n , &a , &b)){
memset(save , 0 , sizeof(save)) ;
for(ll i = 0 ; i < n ; i ++ ){
scanf("%lld %lld" , &save[i][0] , &save[i][1]) ;
}
ll ans = 0 ;
if( a != 0){
m.clear() , m2.clear() ;
dfs() ; dfs2() ;
map<ll , ll> :: iterator it ;
it = m2.begin() ;
ans += m[0] + m2[0] ; //+ m[0] * m2[0] ;
while(it != m2.end()) {
ll a = it->first ;
ll b = it->second ;
ans += m[-a] * b ;
it ++ ;
}
}else{
ll temp = 0 ;
for(ll i = 0 ; i < n ; i ++ ) if(!save[i][0]) temp ++ ;
ans = (1LL<<temp) - 1 ;
///ans = pow(temp) - 1; also fine
}
printf("%lld\n" , ans ) ;
}
return 0 ;
}
相关文章推荐
- XVII Open Cup named after E.V. Pankratiev. XXI Ural Championship
- XVII Open Cup named after E.V. Pankratiev. GP of Moscow Workshops
- XVII Open Cup named after E.V. Pankratiev. GP of Two Capitals
- 【找规律】【递归】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem F. Doubling
- 【枚举】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem D. Cutting Potatoes
- 【推导】【贪心】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem H. Path or Coloring
- XVII Open Cup named after E.V. Pankratiev. GP of Tatarstan
- XVII Open Cup named after E.V. Pankratiev. Grand Prix of America (NAIPC-2017)
- 【分块】【暴力】XVII Open Cup named after E.V. Pankratiev Grand Prix of Moscow Workshops, Sunday, April 23, 2017 Problem I. Rage Minimum Query
- XVII Open Cup named after E.V. Pankratiev. GP of SPb
- XVII Open Cup named after E.V. Pankratiev Grand Prix of Moscow Workshops, Sunday, April 23, 2017 Problem K. Piecemaking
- XVII Open Cup named after E.V. Pankratiev Grand Prix of Moscow Workshops, Sunday, April 23, 2017 Problem D. Great Again
- XVII Open Cup named after E.V. Pankratiev. GP of Siberia, Division 1
- Problem A. Array Factory XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016
- 【推导】【构造】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem E. Space Tourists
- 【opencup】XVI Open Cup named after E.V. Pankratiev. GP of SPB K.Captain Tarjan【树形dp】
- Problem A. Arithmetic Derivative-XVII Open Cup named after E.V. Pankratiev||找规律&数学&DFS
- XIII Open Cup named after E.V. Pankratiev. GP of SPb
- XIV Open Cup named after E.V. Pankratiev. GP of SPb
- 【枚举】【最小表示法】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem F. Matrix Game