Codeforces Round #238 (Div. 1) 解题报告
Problem A Unusual Product
思路:奇数次操作去反即可。
代码如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /************************************************** 2 * Author : xiaohao Z 3 * Blog : http://www.cnblogs.com/shu-xiaohao/ 4 * Last modified : 2014-03-22 23:23 5 * Filename : Codeforce_238_1_A.cpp 6 * Description : 7 * ************************************************/ 8 9 #include <iostream> 10 #include <cstdio> 11 #include <cstring> 12 #include <cstdlib> 13 #include <cmath> 14 #include <algorithm> 15 #include <queue> 16 #include <stack> 17 #include <vector> 18 #include <set> 19 #include <map> 20 #define MP(a, b) make_pair(a, b) 21 #define PB(a) push_back(a) 22 23 using namespace std; 24 typedef long long ll; 25 typedef pair<int, int> pii; 26 typedef pair<unsigned int,unsigned int> puu; 27 typedef pair<int, double> pid; 28 typedef pair<ll, int> pli; 29 typedef pair<int, ll> pil; 30 31 const int INF = 0x3f3f3f3f; 32 const double eps = 1E-6; 33 const int LEN = 1010; 34 int Map[LEN][LEN]; 35 36 int main() 37 { 38 // freopen("in.txt", "r", stdin); 39 40 int n; 41 while(scanf("%d", &n)!=EOF){ 42 for(int i=0; i<n; i++){ 43 for(int j=0; j<n; j++){ 44 scanf("%d", &Map[i][j]); 45 } 46 } 47 int ans = 0; 48 for(int i=0; i<n; i++){ 49 int tmp = 0; 50 for(int j=0; j<n; j++){ 51 if(Map[i][j] == 1 && Map[j][i] == 1) tmp ^= 1; 52 } 53 ans ^= tmp; 54 } 55 int q, op, tmp; 56 scanf("%d", &q); 57 for(int i=0; i<q; i++){ 58 scanf("%d", &op); 59 if(op <= 2){ 60 scanf("%d", &tmp); 61 ans^=1; 62 }else { 63 printf("%d", ans); 64 } 65 } 66 printf("\n"); 67 } 68 return 0; 69 }
Problem B Toy Sum
题意:在1-1000000告诉你A集合然后要你取出一个B集合使得A集合中每一个数减一之和为s减B中每一个数之和。
思路:由于每一个数都有唯一对应的另一个数所以对于两个数中只有一个那就输出一下另外一个,然后若是两个都在A中那么计数一下,在最后再找一对替代就可。
代码如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /************************************************** 2 * Author : xiaohao Z 3 * Blog : http://www.cnblogs.com/shu-xiaohao/ 4 * Last modified : 2014-03-22 23:24 5 * Filename : Codeforce_238_1_B.cpp 6 * Description : 7 * ************************************************/ 8 9 #include <iostream> 10 #include <cstdio> 11 #include <cstring> 12 #include <cstdlib> 13 #include <cmath> 14 #include <algorithm> 15 #include <queue> 16 #include <stack> 17 #include <vector> 18 #include <set> 19 #include <map> 20 #define MP(a, b) make_pair(a, b) 21 #define PB(a) push_back(a) 22 23 using namespace std; 24 typedef long long ll; 25 typedef pair<int, int> pii; 26 typedef pair<unsigned int,unsigned int> puu; 27 typedef pair<int, double> pid; 28 typedef pair<ll, int> pli; 29 typedef pair<int, ll> pil; 30 31 const int INF = 0x3f3f3f3f; 32 const double eps = 1E-6; 33 const int LEN = 1000000+10; 34 int n, f[LEN]; 35 36 int main() 37 { 38 // freopen("in.txt", "r", stdin); 39 40 int s = 1000000; 41 while(cin >> n){ 42 memset(f, 0, sizeof f); 43 for(int i=0; i<n; i++){ 44 int tmp; 45 cin >> tmp; 46 f[tmp] = 1; 47 } 48 int cnt = 0; 49 for(int i=1; i<=500000; i++){ 50 if(f[i] == 1){ 51 if(f[s-(i-1)] == 0) f[s-(i-1)] = 2; 52 else cnt++; 53 } 54 if(f[s-(i-1)] == 1){ 55 if(f[i] == 0) f[i] = 2; 56 } 57 } 58 for(int i=1; i<=500000; i++){ 59 if(cnt == 0) break; 60 if(f[i] == 0 && f[s-(i-1)] == 0){ 61 f[i] = f[s-(i-1)] = 2; 62 cnt--; 63 } 64 } 65 int ans = 0; 66 for(int i=1; i<=1000000; i++) if(f[i] == 2) ans++; 67 cout << ans << endl; 68 for(int i=1; i<=1000000; i++){ 69 if(f[i] == 2) cout << i << ' '; 70 } 71 cout << endl; 72 } 73 return 0; 74 }
奔跑吧!少年!趁着你还年轻