本文主要是介绍2014 Multi-University Training Contest 7小记,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1003 数学 , 先暴力再解方程。
在b进制下是个2 , 3 位数的 大概是10000进制以上 。这部分解方程
2-10000 直接暴力
typedef long long LL ;LL n ;
int ok(int b){LL m = n ;int c ;while(m){c = m % b ;if(c == 3 || c == 4 || c == 5 || c == 6){m /= b ;continue ;}return 0 ;}return 1 ;
}LL d[4] = {3LL , 4LL , 5LL , 6LL} ;int gao(LL a , LL b , LL c){LL delta = b * b - a * c * 4 ;if( delta < 0 ) return 0 ;double sq = sqrt(double(delta)) ;LL s = LL (sq) ;if(s * s == delta){LL a2 = a * 2 ;LL x = - b + s ;int t = 0 ;if( (x > 0) && (x % a2) == 0 ){x = x / a2 ;if(x > 10000) t++ ;}x = - b - s ;if( (x > 0) && (x % a2) == 0 ){x = x / a2 ;if(x > 10000) t++ ;}return t ;}return 0 ;
}int main(){int t , i , j , k , sum , T = 1 ;LL x , y , z ;cin>>t ;while(t--){cin>>n ;printf("Case #%d: " , T++) ;if(n == 3 || n == 4 || n == 5 || n == 6){puts("-1") ;continue ;}sum = 0 ;for(i = 2 ; i <= 10000 ; i++){if(ok(i)) sum++ ;}for(i = 0 ; i < 4 ; i++){x = d[i] ;for(j = 0 ; j < 4 ; j++){y = d[j] ;if( (n > y) && ( (n-y) % x) == 0 ){LL b = (n - y) / x ;if(b > 10000) sum++ ;}}}for(i = 0 ; i < 4 ; i++){x = d[i] ;for(j = 0 ; j < 4 ; j++){y = d[j] ;for(k = 0 ; k < 4 ; k++){z = d[k] ;sum += gao(x , y , z - n) ;}}}cout<< sum << endl ;}return 0 ;
}
1005 DP ,但有个贪心行政
blue影响时间, green影响值, red直接算 ,red放在尾巴最好了。
枚举尾巴red的个数。
dp[i][j] 截止到i位,j个blue的最大值。
typedef long long LL ;const int maxn = 1508 ;
LL dp[maxn][maxn] ;int main(){int T , kas = 1 ;LL n , x , y , z , t , g , b , r , s , i , j ;cin>> T ;while(T--){cin>>n>>x>>y>>z>>t ;memset(dp , 0 , sizeof(dp)) ;for(i = 1 ; i <= n ; i++){for(j = 0 ; j <= i ; j++){if(j >= 1)dp[i][j] = max( dp[i-1][j-1] + (i - j) * y * (t + (j -1)* z) ,dp[i-1][j] + (i-j-1) * y * (t + j * z) ) ;else dp[i][j] = dp[i-1][j] + (i-j-1) * y * (t + j * z) ;}}s = 0 ;for(r = 0 ; r <= n ; r++){for(b = 0 ; b <= n - r ; b++){g = n - r - b ;s = max(s , dp[n-r][b] + r * (g * y + x) * (b * z + t)) ;}}printf("Case #%d: " , kas++) ;cout << s << endl ;}return 0 ;
}
1007 hash完再暴力
const int maxn = 100008 ;int x[maxn][2] , c[maxn] ;
int a[maxn*5] ;struct state{int id ;int cn ;state(){}state(int i , int j) : id(i) , cn(j){}
};
vector<state> row[maxn*5] , col[maxn*5] ;
vector<state> :: iterator it ;int query[maxn][2] , ask[maxn] ;int main(){int t , i , k , n , m , cnt , T = 1 , q ;cin>>t ;while(t--){cin>>n>>m>>k ;cnt = 0 ;for(i = 1 ; i <= k ; i++){scanf("%d%d%d" , &x[i][0] , &x[i][1] , &c[i]) ;a[cnt++] = x[i][0] ;a[cnt++] = x[i][1] ;}cin>>q ;for(i = 1 ; i <= q ; i++){scanf("%d%d%d" , &ask[i] , &query[i][0] , &query[i][1]) ;a[cnt++] = query[i][0] ;a[cnt++] = query[i][1] ;}sort(a , a + cnt) ;cnt = unique(a , a + cnt) - a ;for(i = 1 ; i <= k ; i++){x[i][0] = upper_bound(a , a + cnt , x[i][0]) - a ;x[i][1] = upper_bound(a , a + cnt , x[i][1]) - a ;}for(i = 0 ; i <= cnt ; i++){row[i].clear() ;col[i].clear() ;}for(i = 1 ; i <= k ; i++){row[x[i][0]].push_back(state(x[i][1] , c[i])) ;col[x[i][1]].push_back(state(x[i][0] , c[i])) ;}printf("Case #%d:\n" , T++) ;for(int r = 1 ; r <= q ; r++){int d = upper_bound(a , a + cnt , query[r][0]) - a ;int e = upper_bound(a , a + cnt , query[r][1]) - a ;int ty = ask[r] ;if(ty == 1){if(row[d].size() == 0 || row[e].size() == 0) continue ;for(it = row[d].begin() ; it != row[d].end() ; it++){int co = it->id ;for(i = 0 ; i < col[co].size() ; i++){if(col[co][i].id == d) col[co][i].id = e ;}}for(it = row[e].begin() ; it != row[e].end() ; it++){int co = it->id ;for(i = 0 ; i < col[co].size() ; i++){if(col[co][i].id == e) col[co][i].id = d ;}}swap(row[d] , row[e]) ;}else if(ty == 2){if(col[d].size() == 0 || col[e].size() == 0) continue ;for(it = col[d].begin() ; it != col[d].end() ; it++){int ro = it->id ;for(i = 0 ; i < row[ro].size() ; i++){if(row[ro][i].id == d) row[ro][i].id = e ;}}for(it = col[e].begin() ; it != col[e].end() ; it++){int ro = it->id ;for(i = 0 ; i < row[ro].size() ; i++){if(row[ro][i].id == e) row[ro][i].id = d ;}}swap(col[d] , col[e]) ;}else{int ans = 0 ;for(it = row[d].begin() ; it != row[d].end() ; it++){if(it->id == e){ans = it->cn ;break ;}}printf("%d\n" , ans) ;}}}return 0 ;
}
这篇关于2014 Multi-University Training Contest 7小记的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!