您的位置:首页 > 其它

20161027校内训练

2016-10-29 22:03 459 查看
由于自己比较懒,所以堆到周末来写当天的题解,我发现自己是真的水。

T1 Base

NOIP的题目如果想的太难的话,真心会把自己绕进去,其实只需要暴力就可以了。

/*
ID:Agreement
LANG:C++
*/
// Invincible
#include <bits/stdc++.h>
#define rep( i , l , r ) for( int i = (l) ; i <= (r) ; ++i )
#define per( i , r , l ) for( int i = (r) ; i >= (l) ; --i )
#define erep( i , u ) for( int i = head[(u)] ; ~i ; i = e[i].nxt )
using namespace std;
inline int _read(){
register int x = 0 , f = 1;
register char ch = getchar();
while( ch > '9' || ch < '0' ) { if( ch == '-' ) f = -1; ch = getchar(); }
while( ch >= '0' && ch <= '9' ){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
void FileInOut(){
freopen( "base.in" , "r" , stdin );
freopen( "base.out" , "w" , stdout );
}
const int maxn = 100 + 5;
typedef long long ll;
ll N , M;
char s[maxn];
int main(){
FileInOut();
int T = 0;
scanf("%d" , &T);
while( T-- ){
scanf("%I64d%I64d%s" , &N , &M , s );
int l = strlen( s ) , flg = 1 , mx = 0;
rep( i , 0 , l - 1 ) mx = max( mx , (int)(s[i] - '0') );
rep( b , mx + 1 , 16 ){
ll t = 0;
rep( i , 0 , l - 1 ) t = t * (ll)b + (ll)( s[i] - '0' );
if( t % M == 0 && ( t / M == N ) )  printf("%d\n" , b) , flg = 0;
}
if( flg == 1 ) printf("0\n");
}
return 0;
}


T2 Perm

是关于置换的一道题,有点意思,开始没有能够想到标算。后来想了一下也不是很难,就是求一下其中所有循环节长度的公倍数。但是十分的厉害,在求lcm的时候不能用除法,MOD不是素数并且不能用exgcd,这样就很恶心,只能够用拆分因数的方法来求解,>-<。

/*
ID:Agreement
LANG:C++
*/
// Invincible
#include <bits/stdc++.h>
#define rep( i , l , r ) for( int i = (l) ; i <= (r) ; ++i )
#define per( i , r , l ) for( int i = (r) ; i >= (l) ; --i )
#define erep( i , u ) for( int i = head[(u)] ; ~i ; i = e[i].nxt )
using namespace std;
inline int _read(){
register int x = 0 , f = 1;
register char ch = getchar();
while( ch > '9' || ch < '0' ) { if( ch == '-' ) f = -1; ch = getchar(); }
while( ch >= '0' && ch <= '9' ){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
void FileInOut(){
freopen( "perm.in" , "r" , stdin );
freopen( "perm.out" , "w" , stdout );
}
typedef long long ll;
const int maxn = 1e5 + 5 ;
const ll MOD = 19184192ll;
class Node{
public:
int v , p;
} a[maxn];
bool used[maxn];
int pre[maxn] , t[maxn];
inline bool cmp( const Node &a , const Node &b ) { return a.v < b.v; }
int main(){
FileInOut();
int N = _read();
rep( i , 1 , N ) a[i].v = _read() , a[i].p = i , pre[i] = a[i].v;
sort( a + 1 , a + 1 + N , cmp );
rep( i , 1 , N ) if( a[i].v == pre[i] ) used[i] = 1;
ll l = 0 , ans = 1ll ;
rep( i , 1 , N ) if( !used[i] ){
used[i] = 1 , l = 1ll;
for( int j = a[i].p ; 0 == used[j] ; j = a[j].p ) ++l , used[j] = 1;
if( l ){
int _t = 0;
for( int j = 2 ; j * j <= l ; ++j )
if( l % j == 0 ){
_t = 0;
while( l % j == 0 ) l /= j , ++_t;
t[j] = max( t[j] , _t );
}
if( l != 1 ) t[l] = max( t[l] , 1 );
}
}
rep( i , 1 , 100000 ) if( t[i] ) while( t[i]-- ) ans = ans * (ll)i % MOD;
cout << ans << endl;
return 0;
}


T3 24点

一道只要时间就能做出来的推断题,没什么难度,就直接写代码了。

/*
ID:Agreement
LANG:C++
*/
// Invincible
#include <bits/stdc++.h>
#define rep( i , l , r ) for( int i = (l) ; i <= (r) ; ++i )
#define per( i , r , l ) for( int i = (r) ; i >= (l) ; --i )
#define erep( i , u ) for( int i = head[(u)] ; ~i ; i = e[i].nxt )
using namespace std;
inline int _read(){
register int x = 0 , f = 1;
register char ch = getchar();
while( ch > '9' || ch < '0' ) { if( ch == '-' ) f = -1; ch = getchar(); }
while( ch >= '0' && ch <= '9' ){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
void FileInOut(){
freopen( "card.in" , "r" , stdin );
freopen( "card.out" , "w" , stdout );
}
int main(){
FileInOut();
int n , tmp , T;
scanf ("%d", &T);
while( T-- ){
scanf ("%d", &n);
if(n<=3)
printf("-1\n");
else if(n==4)
printf("1 * 2\n5 + 3\n6 + 4\n");
else if(n==5)
printf("1 * 2\n3 / 6\n4 - 7\n5 * 8\n");
else if(n==6)
printf("1 + 2\n3 + 4\n5 - 6\n7 + 8\n10 - 9\n");
else if(n==7)
printf("1 + 2\n3 + 8\n9 / 4\n10 + 5\n11 + 6\n12 + 7\n");
else if(n==8)
printf("1 + 2\n3 + 9\n4 - 5\n11 * 6\n12 * 7\n13 * 8\n10 + 14\n");
else if(n==9)
printf("1 + 2\n3 + 10\n4 / 5\n6 / 7\n8 / 9\n11 - 12\n15 - 13\n 16 - 14\n");
else if(n==10)
printf("1 + 2\n3 / 4\n5 / 6\n7 / 8\n9 / 10\n11 + 12\n16 + 13\n17 + 14\n18 + 15\n");
else if(n==11)
printf("1 + 2\n3 / 4\n5 / 6\n7 - 8\n15 * 9\n16 * 10\n17 * 11\n12 + 13\n19 + 14\n20 + 18\n");
else if(n==12)
printf("1 + 2\n3 - 4\n5 * 14\n6 * 15\n7 * 16\n8 * 17\n9 * 18\n10 * 19\n11 * 20\n12 * 21\n13 + 22\n");
else if(n==13)
printf("1 + 2\n3 / 4\n5 / 6\n7 - 8\n17 * 9\n18 * 10\n19 * 11\n20 * 12\n21 * 13\n22 + 14\n23 - 15\n24 - 16\n");
else
{
printf("1 + 2\n3 + 4\n5 + 6\n7 + 8\n9 + 10\n");
printf("%d + %d\n%d + %d\n%d + %d\n",n+1,n+2,n+3,n+4,n+5,n+6);
printf("%d / 11\n%d / 12\n",n+7,n+8);
printf("%d * %d\n",n+9,n+10);
printf("13 - 14\n");
tmp=n-14;
rep( i , 0 , tmp - 1 )
printf("%d * %d\n",n+12+i,15+i);
printf("%d + %d\n",n+11,n+12+tmp);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息