【AtCoder】AGC017

A - Biscuits

dp[i][0/1]表示當前和是偶數還是奇數,直接轉移即可

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 1000005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {res = 0;T f = 1;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}while(c >= '0' && c <= '9') {res = res * 10 + c - '0';c = getchar();}res *= f;
}
template<class T>
void out(T x) {if(x < 0) {x = -x;putchar('-');}if(x >= 10) {out(x / 10);}putchar('0' + x % 10);
}
int N,P;
int a[55];
int64 dp[55][2];
void Solve() {read(N);read(P);for(int i = 1 ; i <= N ; ++i) read(a[i]);dp[0][0] = 1;for(int i = 1 ; i <= N ; ++i) {int k = a[i] & 1;dp[i][0] = dp[i - 1][0];dp[i][1] = dp[i - 1][1];dp[i][k ^ 0] += dp[i - 1][0];dp[i][k ^ 1] += dp[i - 1][1];}out(dp[N][P]);enter;
}
int main() {
#ifdef ivorysifreopen("f1.in","r",stdin);
#endifSolve();
}

B - Moderate Differences

A和B差值在\(N \times C\)\((N-1) \times D\)之間肯定能達到
因為下降操作和上升操作差不多,那么我們默認所有的下降操作都在前面
容易發現,當我們進行\(i\)次至少為\(C\)的下降后
\(-i \times C + (N - 1 - i) \times C\)\(-i \times C + (N - 1 - i) \times D\)之間的也可以達到
且這樣能構造最多的重合的區間

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 1000005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {res = 0;T f = 1;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}while(c >= '0' && c <= '9') {res = res * 10 + c - '0';c = getchar();}res *= f;
}
template<class T>
void out(T x) {if(x < 0) {x = -x;putchar('-');}if(x >= 10) {out(x / 10);}putchar('0' + x % 10);
}
int N;
int64 A,B,C,D;
bool check(int64 a,int64 b) {return B - A >= a && B - A <= b;
}
void Solve() {read(N);read(A);read(B);read(C);read(D);for(int i = 0 ; i <= N - 1 ; ++i) {int64 u = (N - 1 - i) * D - C * i,d = (N - 1 - i) * C - C * i;if(check(d,u)) {puts("YES");return;}u = C * i - (N - 1 - i) * C,d = C * i - (N - 1 - i) * D;if(check(d,u)) {puts("YES");return;}}puts("NO");
}
int main() {
#ifdef ivorysifreopen("f1.in","r",stdin);
#endifSolve();
}

C - Snuke and Spells

假如\(i\)出現了\(A[i]\)次,那么覆蓋\([i - A[i],i]\)這個區間,然后找\([0,L]\)沒有被覆蓋的區間長度,就是答案
可以\(O(1)\)處理修改

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 1000005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {res = 0;T f = 1;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}while(c >= '0' && c <= '9') {res = res * 10 + c - '0';c = getchar();}res *= f;
}
template<class T>
void out(T x) {if(x < 0) {x = -x;putchar('-');}if(x >= 10) {out(x / 10);}putchar('0' + x % 10);
}
int N,M;
int A[MAXN];
int cnt[MAXN],cov[MAXN],ans;
void Solve() {read(N);read(M);for(int i = 1 ; i <= N ; ++i) {read(A[i]);cnt[A[i]]++;cov[A[i] - cnt[A[i]] + 1]++;}for(int i = 1 ; i <= N ; ++i) {if(!cov[i]) ++ans;}int x,y;for(int i = 1 ; i <= M ; ++i) {read(x);read(y);if(A[x] - cnt[A[x]] + 1 >= 1) {if(!--cov[A[x] - cnt[A[x]] + 1]) ++ans;}--cnt[A[x]];A[x] = y;++cnt[A[x]];if(A[x] - cnt[A[x]] + 1 >= 1) {if(!cov[A[x] - cnt[A[x]] + 1]++) --ans;}out(ans);enter;}
}
int main() {
#ifdef ivorysifreopen("f1.in","r",stdin);
#endifSolve();
}

D - Game on Tree

一個點的sg函數值顯然是0,而一個樹加一條邊一個點的sg函數值是這棵樹的sg函數值+1

證明,設新加的邊為\(u,v\)\(u\)\(v\)的祖先,若斷掉新加的邊,則sg值是0

否則斷樹中的邊,sg函數值為\([0,sg[v] - 1]\),從小到大取,使得\(v\)為根游戲狀態為0的那條邊,斷了之后,由于斷掉新邊游戲狀態是0,則這個狀態給\(u\)為根的貢獻是\(1\)

使得\(v\)為根貢獻為1的斷邊狀態,子游戲中斷邊為0的狀態可以轉化為1,再填上斷掉新邊的狀態是0,則這個對\(u\)的貢獻變成了2

以此類推,這種情況游戲狀態就是\(sg[v] + 1\)

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {res = 0;T f = 1;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}while(c >= '0' && c <= '9') {res = res * 10 + c - '0';c = getchar();}res *= f;
}
template<class T>
void out(T x) {if(x < 0) {x = -x;putchar('-');}if(x >= 10) {out(x / 10);}putchar('0' + x % 10);
}
int N;
struct node {int to,next;
}E[MAXN * 2];
int sumE,sg[MAXN],head[MAXN];
void add(int u,int v) {E[++sumE].to = v;E[sumE].next = head[u];head[u] = sumE;
}
void dfs(int u,int fa) {sg[u] = 0;for(int i = head[u]; i ; i = E[i].next) {int v = E[i].to;if(v != fa) {dfs(v,u);sg[u] ^= (sg[v] + 1);}}
}
void Solve() {read(N);int x,y;for(int i = 1 ; i < N ; ++i) {read(x);read(y);add(x,y);add(y,x);}dfs(1,0);if(sg[1]) puts("Alice");else puts("Bob");
}
int main() {
#ifdef ivorysifreopen("f1.in","r",stdin);
#endifSolve();
}

E - Jigsaw

把連在地面上的高度設為正數,不連在地面上的高度設為負數
然后一個點相當于一條邊\((l,r)\)
相當于把整個圖拆成負數點到正數點的若干路徑
只要判斷一個弱聯通圖,負數點是否全為度數是否全負,正數點度數是否全正,然后至少有一個點點度不為0
證明就是歐拉回路,兩兩匹配負數點和正數點,一定會有歐拉回路,斷掉這些邊就是答案

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 10005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {res = 0;T f = 1;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}while(c >= '0' && c <= '9') {res = res * 10 + c - '0';c = getchar();}res *= f;
}
template<class T>
void out(T x) {if(x < 0) {x = -x;putchar('-');}if(x >= 10) {out(x / 10);}putchar('0' + x % 10);
}
int g[405][405],f[405][405],ind[405],H,col[405],all;
int N,A[100005],B[100005],C[100005],D[100005],cnt;
bool vis[405],flag,has[405];
void dfs(int u) {all += ind[u];if(ind[u]) flag = 1;vis[u] = 1;for(int i = 1 ; i <= 2 * H ; ++i) {if(f[u][i] && !vis[i]) dfs(i);}
}
void Solve() {read(N);read(H);for(int i = 1 ; i <= N ; ++i) {read(A[i]);read(B[i]);read(C[i]);read(D[i]);int s,t;if(C[i]) s = C[i];else s = A[i] + H;if(D[i]) t = D[i] + H;else t = B[i];g[s][t]++;ind[t]++;ind[s]--;f[s][t]++;f[t][s]++;has[s] = has[t] = 1;}for(int i = 1 ; i <= H ; ++i) {if(ind[i] < 0) {puts("NO");return;}}for(int i = H + 1 ; i <= 2 * H ; ++i) {if(ind[i] > 0) {puts("NO");return;}}for(int i = 1 ; i <= 2 * H ; ++i) {if(!has[i]) continue;if(!vis[i]) {flag = 0;dfs(i);if(all != 0 || !flag) {puts("NO");return;}}}puts("YES");
}
int main() {
#ifdef ivorysifreopen("f1.in","r",stdin);
#endifSolve();
}

F - Zigzag

dp[i][j][mask]表示第i條邊走了第j步,左邊界是什么
根據限制和每一步的選擇修改左邊界即可
復雜度\(O(n^{2}2^{n})\)

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {res = 0;T f = 1;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}while(c >= '0' && c <= '9') {res = res * 10 + c - '0';c = getchar();}res *= f;
}
template<class T>
void out(T x) {if(x < 0) {x = -x;putchar('-');}if(x >= 10) {out(x / 10);}putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,M,K;
int A[405],B[405],C[405],w[25][25];
int dp[2][21][(1 << 19) + 5];
int inc(int a,int b) {return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {return 1LL * a * b % MOD;
}
void update(int &x,int y) {x = inc(x,y);
}
int lowbit(int x) {return x & (-x);
}
void Solve() {read(N);read(M);read(K);memset(w,-1,sizeof(w));for(int i = 1 ; i <= K ; ++i) {read(A[i]);read(B[i]);read(C[i]);w[A[i]][B[i]] = C[i];}int cur = 0;dp[0][1][0] = 1;for(int i = 1 ; i <= M ; ++i) {for(int j = 1 ; j < N ; ++j) {for(int s = 0 ; s < (1 << N - 1) ; ++s) {if(!dp[cur][j][s]) continue;if(w[i][j] != 1 && !(s >> (j - 1) & 1)) update(dp[cur][j + 1][s],dp[cur][j][s]);if(w[i][j] != 0) {if(s >> (j - 1) & 1) update(dp[cur][j + 1][s],dp[cur][j][s]);else {int t = s - (s & (1 << j) - 1);t -= t & (-t);t ^= (1 << j - 1);t += s & (1 << j) - 1;update(dp[cur][j + 1][t],dp[cur][j][s]);}}}}memset(dp[cur ^ 1],0,sizeof(dp[cur ^ 1]));for(int s = 0 ; s < (1 << N - 1) ; ++s) dp[cur ^ 1][1][s] = dp[cur][N][s];cur ^= 1;}int ans = 0;for(int s = 0 ; s < (1 << N - 1) ; ++s) ans = inc(ans,dp[cur][1][s]);out(ans);enter;
}
int main() {
#ifdef ivorysifreopen("f1.in","r",stdin);
#endifSolve();
}

轉載于:https://www.cnblogs.com/ivorysi/p/10554163.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/248342.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/248342.shtml
英文地址,請注明出處:http://en.pswp.cn/news/248342.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

SQL語法(1、安裝操作)

1、數據庫的系統概述及安裝與基本使用 bilibili可查找安裝視頻百度了解一下 – 使用超級管理員登錄 CONN sys/change_on_install AS SYSDBA ; – 創建c##scott用戶 CREATE USER c##scott IDENTIFIED BY tiger ; – 為用戶授權 GRANT CONNECT,RESOURCE,UNLIMITED TABLESPACE…

java 中文字符和unicode編碼值相互轉化

java 中文字符和unicode編碼值相互轉化 https://blog.csdn.net/u011366045/article/details/79235217 版權聲明&#xff1a;本文為博主原創文章&#xff0c;未經博主允許不得轉載。 https://blog.csdn.net/u011366045/article/details/792352171、引用工具 import com.alibaba.…

Object 及toString() 方法的重寫

Object: 是所有的類的父類 &#xff0c;Object中所有的方法 &#xff0c; 子類都能使用 &#xff0c; 接口不是Object子類。 Person: /*將父類的equals方法 重寫* 不改變父類的源代碼 equals 比較內存地址* 比較兩個成員變量 變量值相等 返回true 不等 返回false* 重…

SQL語法練習

SQL語法練習https://blog.csdn.net/qq_30764991/article/details/81952197員工表建表語句: CREATE TABLE EMP ( ENAME VARCHAR2(30), EMPNO NUMBER(5), DEPTNO NUMBER(5), JOB VARCHAR2(20), HIREDATE DATE, COMM NUMBER(6,2), SAL NUMBER(6,2) ); 部門表建表語句: CREATE TA…

第22章:MongoDB-聚合操作--聚合管道--$out

①$out$out&#xff1a;利用此操作可以將查詢結果輸出到指定的集合里面。②范例&#xff1a;將投影的結果輸出到集合里③④⑤⑥⑦⑧⑨⑩??????????轉載于:https://www.cnblogs.com/Lucky-stars/p/10555296.html

SQL簡單查詢

1、簡單查詢 使用Oracle sql developer使用前&#xff0c;必須開啟的服務&#xff1a; 查詢emp表上的數據&#xff1a; select * from emp; Null為空&#xff0c;空不代表等于沒有&#xff0c;null&#xff01;0. 重新連接后&#xff0c;注意大小寫及空格位&#xff01; 簡…

實用小技巧(一):UIScrollView中上下左右滾動方向的判斷

https://www.jianshu.com/p/93e8459b6dae 2017.06.01 01:13* 字數 674 閱讀 1201評論 0喜歡 12017.06.01 01:13* 字數 674 閱讀 1201評論 0喜歡 1 版本記錄 版本號 時間 V1.0 2017.05.31 前言 ios中又很多實用的小技巧&#xff0c;實現不難很實用&#xff0c;以后我會慢慢的…

less.js

1.變量 2.混入 3.帶參的混入 4.選擇器的繼承&#xff0c;貌似還不支持 5.嵌套規則 6.運算 7.顏色函數 8.條件語句與控制&#xff0c;貌似不支持 9.命名空間 10.注釋 11.作用域 12.字符的插入 13.轉義 14.JavaScript 的賦值轉載于:https://www.cnblogs.com/I-am-fine/archive/20…

SQL限定查詢

1、限定查詢與排序顯示 1.1限定查詢的認識&#xff1a; 列&#xff1a;表中有大數據的信息&#xff0c;對數據進行篩選&#xff0c;查詢到自己想要的信息。 &#xff08;數據過多顯示過慢&#xff0c;或者死機&#xff0c;在已有的樣本數據庫容器CDB轉換為PDB之中&#xff09;…

Centos6.10源碼部署zabbix-3.2.6

環境&#xff1a;Centos6.10 已有lnmp環境 mysql5.7 php7.2 創建zabbix數據庫 mysql> create database zabbix character set utf8 collate utf8_bin; mysql> grant all privileges on zabbix.* to zabbixlocalhost identified by zabbix; 創建zabbix用戶 shell> …

淺談五大Python Web框架

http://www.csdn.net/article/2011-02-17/292058 導讀&#xff1a;作者飛龍寫了一篇《淺談Python Web框架》&#xff0c;文中他介紹了幾個Python Web框架和自己對選擇框架的分析。在他看來&#xff0c;用Django來快速開發一些Web運用是很不錯的選擇。以下是文章內容&#xff1a…

主流瀏覽器和內核及Web標準

目前網絡市場的瀏覽器主流&#xff1a; 課時3&#xff1a;web標準 WEB標準 w3c 萬維網聯盟組織&#xff0c;制定web標準的機構。 網頁主要由三部分組成&#xff1a; 結構&#xff08;Structure&#xff09;、 表現&#xff08;Presentation&#xff09; 行為&#xff08;Beh…

質量屬性六個常見屬性場景(《淘寶網》為例) 15

六個最常見的系統質量屬性分別是&#xff1a;可用性&#xff08;Availability&#xff09;、可修改性&#xff08;Modifiability&#xff09;、性能&#xff08;Performance&#xff09;、安全性&#xff08;Security&#xff09;、可測試性&#xff08;Testability&#xff09…

機器學習中的損失函數 (著重比較:hinge loss vs softmax loss)

https://blog.csdn.net/u010976453/article/details/78488279 1. 損失函數 損失函數&#xff08;Loss function&#xff09;是用來估量你模型的預測值 f(x)f(x) 與真實值 YY 的不一致程度&#xff0c;它是一個非負實值函數&#xff0c;通常用 L(Y,f(x))L(Y,f(x)) 來表示。損失函…

HTML入門第一和第二章

課時4&#xff1a;HTML初識 1、英文名&#xff08;Hyper Text Markup Language&#xff09;超文本標簽語言 對網頁上的內容進行描述 課時5&#xff1a;HTML骨架 課時6&#xff1a;我的第一個頁面及其標簽簡介 課時7&#xff1a;骨架記憶法 課時8&#xff1a;什么是標簽及其分…

mysql 指令

// 授予用戶某些權限GRANT ALL ON *.* TO USERHOST;// 進入mysql訪問特定數據庫mysql -u user -p database_name// 查看數據表結構DESCRIBE table_name;// 加載文本數據到tableLOAD DATA LOCAL INFILE file_path INTO TABLE table_name;// UPDATE語句UPDATE table_name SET col…

flex label 換行

Flex中label換行有兩種情況 在AS中賦值&#xff1a; label.text"Online\r\nResources" 在mxml中賦值&#xff1a; text"OnlineResources" 在flash builder中就可以換行顯示了。左右有四種對齊方式&#xff0c;上下四種對齊方式。 也就是說mx中的label不支持…

H5第一天

移動Web - 基礎&流式布局 目標 了解移動端主要瀏覽器的內核掌握用谷歌瀏覽器調試移動端頁面&#xff08;重要&#xff09;了解布局視口、視覺視口、理想視口使用mate標簽設置理想視口&#xff08;重要&#xff09;了解視網膜屏、物理像素、二倍圖會使用background-size設…

python數據結構之字典(未完成)

字典 dic {key:value} 1.字典特性 key必須是唯一的&#xff0c;值不必是唯一。 值可以是任何數據類型&#xff0c;比如list&#xff0c;tuple&#xff0c;字符&#xff0c;數值等。key只能是不可變的數據類型。 同一個key不允許重復&#xff0c;如果出現重復&#xff0c;后一個…

一個textView中的文字設置成兩種顏色

使用Spannablestring和ForegroundColorSpan。 SpannableString string2 new SpannableString("自助導入會員和連續開單\n3個月可獲得免費短信服務");ForegroundColorSpan span2 new ForegroundColorSpan(getResources().getColor(R.color.worker_main_worker));str…