直接輸出
php代碼?| _ ____ _____ _____ |
| | | _ \ / ____|/ ____| |
| | | |_) | | __| | __ |
| _ | | _<| | |_ | | |_ | |
| | |__| | |_) | |__| | |__| | |
| \____/|____/ \_____|\_____| |
將原矩陣的每個(gè)字符輸出兩次,同時(shí)每行也輸出兩次
#includeusing namespace std;
using i64 = long long;
int main()
{std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n,m;
std::cin >>n >>m;
for (int i = 0; i< n; i ++) {string s;
std::cin >>s;
for (int u = 0; u< 2; u ++) {for (int j = 0; j< m; j ++) {for (int k = 0; k< 2; k ++) {std::cout<< s[j];
}
}
std::cout<< "\n";
}
}
return 0;
}
由于題目數(shù)據(jù)小,不搞一些花哨操作,直接判斷每組尋問(wèn)中是否有被抓的可能
#includeusing namespace std;
using i64 = long long;
void solve()
{int a,b,c,d;
std::cin >>a >>b >>c >>d;
int q;
std::cin >>q;
bool ok = false;
while (q -- ) {int x;
std::cin >>x;
if ((x >= a and x<= b) or (x >= c and x<= d)) ok = true;
}
if (ok) std::cout<< "Y\n";
else std::cout<< "N\n";
}
int main()
{std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >>T;
while (T -- ) {solve();
}
return 0;
}
#includeusing namespace std;
#define int long long
void solve()
{int n,m,x;
std::cin >>n >>m >>x;
std::vectora(n + 10),b(m + 10),A(x + 10),S(x + 10);
for (int i = 1; i<= n; i ++) {std::cin >>a[i];
}
for (int j = 1; j<= m; j ++) {std::cin >>b[j];
}
for (int i = 1; i<= x; i ++) {for (int j = 1; j<= n; j ++) {if (i<= a[j] or S[i - a[j]] == 0) {A[i] = 1;
}
}
for (int j = 1; j<= m; j ++) {if (i<= b[j] or A[i - b[j]] == 0) {S[i] = 1;
}
}
}
if (A[x]) std::cout<< "AsindE\n";
else std::cout<< "slwang\n";
}
signed main()
{std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >>T;
while (T -- ) {solve();
}
return 0;
}
bi為a中下標(biāo)為i的倍數(shù)的元素和
,即b1 = a(1-n),b2 = a(2,4…).所以b1包含了a數(shù)組的所有元素。 我們可以通過(guò)
消除其他項(xiàng)與b1共有的數(shù)。如圖
要消去b4中的a8,b3中的a6,b2中的a4,a6,a8.最后通過(guò)b1便可得出a1
#includeusing namespace std;
#define int long long
signed main()
{std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >>n;
std::vectorb(n + 1);
for (int i = 1; i<= n; i ++) {std::cin >>b[i];
}
for (int i = n; i >= 1; i --) {//逆序消
for (int j = i + i; j<= n; j += i) {b[i] -= b[j];
}
}
std::cout<< b[1]<< "\n";
return 0;
}
小細(xì)節(jié):枚舉bi的時(shí)候要逆序枚舉,這樣消可以省去很多麻煩,附圖:按照題意模擬即可
#includeusing namespace std;
using i64 = long long;
void solve()
{string s;
std::cin >>s;
int n = s.size();
for (int i = 0; i< n; i ++) {if (!i) {s[i] = tolower(s[i]);
continue;
}
if (s[i] >= 'A' and s[i]<= 'Z') {s[i] = tolower(s[i]);
s[i - 1] = toupper(s[i - 1]);
}
}
s[n - 1] = toupper(s[n - 1]);
std::cout<< s<< "\n";
}
int main()
{std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >>T;
while (T -- ) {solve();
}
return 0;
}
dfs; 明顯可以看出答案是一條鏈,我們應(yīng)該找到一個(gè)入度為0的點(diǎn)進(jìn)行搜,取搜到的大值即可。
這里直接以每一個(gè)點(diǎn)作為根節(jié)點(diǎn)搜了起來(lái)
#includeusing namespace std;
#define int long long
const int N = 5e3 + 10;
std::vectora(N);
std::vector>>g(N);
std::vectorf(N);
int res = 0;
void dfs(int u,int fa)
{int ans = 0;
for (auto [k,v] : g[u]) {if (k == fa) continue;
dfs(k,u);
res = std::max(res,ans + a[u] + v + f[k]);
ans = std::max(ans,f[k] + v);
f[u] = std::max(f[u],ans);
}
f[u] += a[u];
res = std::max(res,f[u]);
}
signed main()
{std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >>n;
for (int i = 1; i<= n; i ++) {std::cin >>a[i];
}
for (int i = 1; i< n; i ++) {int a,b,c;
std::cin >>a >>b >>c;
g[a].push_back({b,c});
g[b].push_back({a,c});
}
dfs(1,1);
std::cout<< res<< "\n";
return 0;
}
匿名函數(shù)dfs寫(xiě)完一直報(bào)錯(cuò),調(diào)了半小時(shí),所幸直接仍外邊了,不知道為啥。很煩!一種簡(jiǎn)單的解法:直接用1和-1構(gòu)造這個(gè)矩陣,容易知道,只有當(dāng)1和-1交替出現(xiàn)時(shí)才能滿足題意
#includeusing namespace std;
#define int long long
void solve()
{int n,m;
std::cin >>n >>m;
for (int i = 1; i<= n; i ++) {for (int j = 1; j<= m; j ++) {std::cout<< ((i + j) % 2 ? "1" : "-1")<< " \n"[j == m];
}
}
}
signed main()
{std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >>T;
while (T -- ) {solve();
}
return 0;
}
這里起初是用異或?qū)懙?,奈何某些地方?jīng)]有被賦上值。最后沒(méi)時(shí)間了,改了改I題最后沒(méi)時(shí)間寫(xiě)了,有空再補(bǔ)
考慮使用并查集,最后輸出每個(gè)的祖先
#includeusing namespace std;
#define int long long
const int N = 2e5 + 10;
int pre[N];
int find(int x)
{return x == pre[x] ? pre[x] : pre[x] = find(pre[x]);
}
signed main()
{std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n,m;
std::cin >>n >>m;
std::vectora(n + 1);
for (int i = 1; i< N; i ++) {pre[i] = i;
}
for (int i = 1; i<= n; i ++) {std::cin >>a[i];
}
while (m --) {int a,b;
std::cin >>a >>b;
int fa = find(a);
int fb = find(b);
if (fa != fb) {pre[fa] = fb;
}
}
for (int i = 1; i<= n; i ++) {std::cout<< find(a[i])<< " \n"[i == n];
}
return 0;
}
最后輸出是一定要再查一下祖先,否則會(huì)出現(xiàn)一些點(diǎn)的祖先沒(méi)有更新過(guò)來(lái)數(shù)學(xué)題,a與a + x互質(zhì)等價(jià)于x 與 a 互質(zhì),所以暴力找與x互質(zhì)的數(shù)即可
#includeusing namespace std;
using i64 = long long;
void solve()
{int n;
std::cin >>n;
for (int i = 2; ; i ++) {if (__gcd(i,n) == 1) {std::cout<< i<< " "<< i + n<< "\n";
return;
}
}
}
int main()
{std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >>T;
while (T -- ) {solve();
}
return 0;
}
將n拼起來(lái),取模找大值,枚舉到m與p的最小值
#includeusing namespace std;
#define int long long
//a^b%p
templateT qmi(T a, int b,T p) {T res = 1 % p;
while (b)
{if (b & 1) res = res * a % p;
a = a * a % p;
b >>= 1;
}
return res;
}
signed main()
{std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n,m,p;
std::cin >>n >>m >>p;
int t = n,c = 0;
while (t) {t /= 10;
c ++;
}
int w = qmi(1ll * 10,c,p),res = 0;
for (int i = 1; i<= std::min(m,p); i ++) {t = (t * w + n) % p;
res = std::max(res,t);
}
std::cout<< res<< "\n";
return 0;
}
幾何題能不能死一死
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
當(dāng)前文章:牛客:浙江農(nóng)林大學(xué)2022年新生杯程序設(shè)計(jì)競(jìng)賽(同步賽)VP題解-創(chuàng)新互聯(lián)
文章轉(zhuǎn)載:http://jinyejixie.com/article42/dsiohc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營(yíng)銷型網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、網(wǎng)站收錄、企業(yè)網(wǎng)站制作、自適應(yīng)網(wǎng)站、手機(jī)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容