解题报告ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
还是太弱了,每次DIV2只能做两道题,争取以后能在一个小时之内做出两道题,或者能A三道题吧。
A. A Serial Killer
题目连接:http://codeforces.com/problemset/problem/776/A
题意:
给定两个名字,接下来是n天,接下来n行每行两个名字,第一个名字是第一天被杀的(前一天两个名字之一) 第二个名字是被杀之后替换上去的人
让你输出每天都是谁活着。
非常水,直接匹配之后替换名字就好
1 #include<cstdio> 2 #include<cstdlib> 3 #include<algorithm> 4 #include<vector> 5 #include<set> 6 #include<map> 7 #include<cstring> 8 #include<iostream> 9 using namespace std ; 10 11 12 int main() 13 { 14 15 string s1,s2; 16 int n ; 17 cin >> s1 >> s2 >> n ; 18 cout << s1 << ' ' << s2 << endl ; 19 for( int i = 1 ; i <= n ; i++) 20 { 21 string s3 , s4 ; 22 cin >> s3 >> s4 ; 23 if( s1 == s3 ) 24 s1 = s4 ; 25 else if ( s2 == s3 ) 26 s2 = s4 ; 27 cout << s1 << ' ' << s2 << endl ; 28 } 29 return 0 ; 30 }
B. Sherlock and his girlfriend
题目连接: http://codeforces.com/problemset/problem/776/B
题意:
给定n个宝石,宝石价值为2到n+1元,要求如果一个数是另外一个数的质因数,那么这两个数字颜色不能相同,问最少需要多少种颜色染色n个宝石,并输出每个宝石的颜色。
被谷歌翻译坑了……
prime divisor 谷歌翻译成了 主因数,我以为是因数问题,于是想着质因数分解。
后来在群里发现是质因数之后,答案就非常简单了,只需要一或二两种颜色就可以染色。
需要注意的是数据范围,朴素求素数会T,要用线性筛。
1 #include<cstdio> 2 #include<cstdlib> 3 #include<algorithm> 4 #include<vector> 5 #include<set> 6 #include<map> 7 #include<cstring> 8 #include<iostream> 9 #include<cmath> 10 using namespace std ; 11 12 int a[100100]; 13 /*bool isprime( int n ) 14 { 15 if( n == 2 ) 16 return true ; 17 for( int i = 2 ; i <= sqrt(n) + 1 ; i++) 18 if( n % i == 0 ) 19 return false ; 20 return true ; 21 }*/ 22 23 bool temp[100100]; 24 25 void init(int n) 26 { 27 for( int i = 2 ; i <= n+1 ; i++) 28 temp[i] = true; 29 int j = 2 ; 30 for( int i = 2 ; i <= n+1 ; i++) 31 { 32 if( temp[i] == false ) 33 continue ; 34 while( i* j <= n+1 ) 35 temp[i*j] =false , j++ ; 36 j = 2 ; 37 } 38 39 } 40 int main() 41 { 42 int n ; 43 cin >> n ; 44 if( n == 1 ) 45 { 46 cout << 1 << endl ; 47 cout << 1 << endl ; 48 return 0 ; 49 } 50 51 if( n == 2 ) 52 { 53 cout << 1 << endl ; 54 cout <<1 <<' ' << 1 << endl ; 55 return 0 ; 56 } 57 58 init(n) ; 59 cout << 2 << endl ; 60 for( int i = 2 ; i <= n+1 ; i++) 61 { 62 if( temp[i] ) 63 cout << 1 << ' ' ; 64 else 65 cout << 2 << ' ' ; 66 } 67 cout << endl ; 68 return 0 ; 69 }
浙公网安备 33010602011771号