标签:sizeof 不能 for alt typedef ima 排列 ali bool
题意&思路:Wuuuu~,其实就是问总和是不是为M
#include<iostream> #include<cstring> #include<cmath> #include<algorithm> #define rep(i,n) for(i=1;i<=n;++i) #define ms(a,n) memset(a,n,sizeof(a)) #define maxn 100005+5 #define inf 0x3f3f33f3f using namespace std; typedef long long ll; ll t, n, temp, m, a, b; string s; int main() { cin >> t; ll i; while (t--) { cin >> n >> m; ll sum = 0; rep(i, n) { cin >> temp; sum += temp; } if (sum == m)cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
题意:给一个正整数N,要求构造一个N阶矩阵,其中每行每列的和都为一个素数,并且矩阵中不能含有素数,并且每个数在都为非负数的同时小于1E5;
思路:考虑构造一个大小为N的数组,其中含有(N-1)个A(满足题意的数),一个1;数组的和为素数(这样的数组是存在的,但我无法证明);然后是对角线为1,其他为A的矩阵易知满足题意
#include<iostream> #include<cstring> #include<cmath> #include<algorithm> #define rep(i,n) for(i=1;i<=n;++i) #define ms(a,n) memset(a,n,sizeof(a)) #define maxn 100005+5 #define inf 0x3f3f33f3f using namespace std; typedef long long ll; ll t, n, temp, m, a, b; bool isp[50005]; int main() { ios::sync_with_stdio(false); ms(isp, true); for (int i = 2; i <= 50000; ++i) { if (isp[i]) { for (int j = 2 * i; j <= 50000; j+=i) { isp[j] = false; } } } isp[0] = isp[1] = false; cin >> t; ll i; while (t--) { cin >> n; for (int i = 1;; ++i) { if (!isp[i]) { if (isp[(n - 1) * i + 1]) { temp = i; break; } } } for (i = 1; i <= n; i++) { if (i == 1)cout << 1; else cout << temp; for (int j = 2; j <= n; ++j) { if (i == j)cout << " " << 1; else cout << " " << temp; } cout << endl; } cout << endl; } return 0; }
题意:如题
思路:统计在二分搜索的过程中,MID分别大于小于POS的个数,记为A ,B。MID大于POS时A++,否则B++;
在N-X的数中,要选出A个数,1~X-1中选出B个数(全排列),满足二分搜索的条件,其余的就可以乱放了(注意边界条件)
#include<iostream> using namespace std; typedef long long ll; ll mod = 1e9 + 7; ll n, x, pos, l, r, a = 0, b = 0, ans = 1; int main(){ ios::sync_with_stdio(false); cin >> n >> x >> pos; l = 0; r = n; while (l < r) { ll mid = (l + r) >> 1; if (mid == pos) l = mid + 1; else if (mid > pos) { r = mid; a++; } else if (mid < pos) { l = mid + 1; b++; } } if (b >= x || a > n - x) cout << 0 << endl; else { for (ll i = x - 1, j = 1; j <= b; i--, j++) ans = (ans * i) % mod; for (ll i = n - x, j = 1; j <= a; i--, j++) ans = (ans * i) % mod; for (ll i = 1; i <= n - a - b - 1; i++) ans = (ans * i) % mod; cout << ans << endl; } return 0; }
Codeforces Round #678 (Div. 2)A B C 题解
标签:sizeof 不能 for alt typedef ima 排列 ali bool
原文地址:https://www.cnblogs.com/ggnpgl/p/14551084.html