简单的网站构建的基本流程,wordpress 伪静态配置,北京域名,尚硅谷python基础教程D.The Game of Eating
思路#xff1a;考虑贪心。每个人都会选择一道对于自身价值最大的菜#xff0c;但考虑到其他人会帮自己提供一定的贡献#xff0c;即样例二#xff0c;第一个只需要点第三道菜#xff0c;第二个人点第四道菜#xff0c;自动帮第一个人补全了第四道…
D.The Game of Eating
思路考虑贪心。每个人都会选择一道对于自身价值最大的菜但考虑到其他人会帮自己提供一定的贡献即样例二第一个只需要点第三道菜第二个人点第四道菜自动帮第一个人补全了第四道价值最大的菜所以当前人的选择可能要考虑到后续人员的影响既然如此我们考虑最后一个人即最后一个进行点菜时没有人对其选择造成影响然后依次往前推每个人取当前的最大价值即可。
#include bits/stdc.husing namespace std;
const int N 1e6 10;
typedef long long ll;
typedef pairll, ll pll;
typedef arrayint, 3 p3;
int mod 51123987;
const int maxv 4e6 5;int st[2005];
int a[2005][2005];
void solve()
{memset(st,0,sizeof st);int n,m,k;cinnmk;for(int i1;in;i){for(int j1;jm;j) cina[i][j];}int resk%n;if(res0) resn;vectorint ans;for(int ires;i1;i--){int val0;int c0;for(int j1;jm;j){if(st[j]) continue;if(a[i][j]val){vala[i][j];cj;}}st[c]1;ans.push_back(c);if(i1) in1;k--;if(k0) break;}sort(ans.begin(),ans.end());for(auto x: ans) coutx ;coutendl;}int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;t 1;cin t;while (t--){solve();}//coutendl;system(pause);return 0;
}E.The Game of Eating
思路考虑去枚举每个k因为k最多只能到18数据范围很小然后按照题意去模拟即可。
#includebits/stdc.husing namespace std;
const int N1e55;
typedef long long ll;
typedef pairll,ll pll;
int mod998244353;
const int maxv4e65;void solve()
{ ll n;cinn;ll x10;for(int i0;;i){if(i0) x1;else x*10;if(x*n1e18) break;ll tsqrtl(x*n);if(t*t/xn) {couttendl;return ;}if((t1)*(t1)/xn){coutt1endl;return; }}cout-1endl;
}int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;t1;cint;while(t--){solve();}system(pause);return 0;
}F.Link with Chess Game
思路官方题解给定的是二分图博弈以后有空在去了解吧。
当n为偶数时先手必胜当为奇数时和r,g,b的状态相同当rgb为偶数的时候先手必胜。
#include bits/stdc.husing namespace std;
const int N 1e6 10;
typedef long long ll;
typedef pairint, int pll;
typedef arrayint, 3 p3;
int mod 1e9 7;
const int maxv 4e6 5;void solve()
{int n,r,g,b;cinnrgb;if(n%20){coutAliceendl;return ;}else{if((rgb)%20){coutAliceendl;return ;}}coutBobendl;}int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;t 1;cin t;while (t--){solve();}system(pause);return 0;
}G.Link with Centrally Symmetric Strings
题意题目给定关于回文对称的新定义然后问是否可以将给定字符串拆解成若干个回文字符串。
思路关于回文字符串我们可以用马拉车算法处理出每个位置上的回文半径然后设置一个变量f 在遍历整个字符串时去记录最长的不合法的长度若当前位置的回文半径大于不合法长度那么直接跳到if处。最后变量值若为0则表示为合法字符串。
接下来来证明为什么这么做是对的
1 若给定字符串s不嫩被拆解成若干个回文对称字符串即存在某一些位置不是回文对称的那么从该位置开始变量f值会一直大于后续的所有的回文半径。因为只要出现回文半径大于f的情况f就会被置为0重新开始。
2 若给定字符串能够被拆解成若干个回文对称字符串那么每当匹配到回文对称中心时此时的位置距离前一个回文字符串的结尾距离即为p[i],而此时的回文半径长度肯定是大于f的所以会一直匹配下去。
#include bits/stdc.husing namespace std;
const int N 1e6 10;
typedef long long ll;
typedef pairint, int pll;
typedef arrayint, 3 p3;
int mod 1e9 7;
const int maxv 4e6 5;int z[300];
int p[N*2];void solve()
{string s;cins;string a;a#;for(int i0;is.size();i){a.push_back(s[i]);a.push_back(#);}a a;int na.size();for(int i1;in;i){if(z[a[i]]a[i]) p[i]1;else p[i]0;}int r0,m0;for(int i1;in;i){if(ir) p[i]min(p[m*2-i],r-i1);while(z[a[p[i]i]]a[i-p[i]]p[i]in) p[i];if(ip[i]-1r){rip[i]-1;mi;}}int f0;for(int i1;in;i){//coutp[i] ;if(p[i]f){if;f0;}else f;}if(!f){coutYes\n;}else coutNo\n;}int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;t 1;cin t;z[b]q;z[q]b;z[d]p;z[p]d;z[n]u;z[u]n;z[o]o;z[s]s;z[x]x;z[z]z;z[#]#;while (t--){solve();}system(pause);return 0;
}思考为什么是将当前位置加上变量f而不是直接让i加上回文半径p考虑下述情况 当我们将字符串的黄色部分遍历完后保证此种情况l1的右界小于l2此时f0当我们遍历到对称中心l1时我们若直接让i加上对应的回文半径p[l1]时会直接变为l2附近那么后续会出现还有一半的蓝色部分不为回文字符串。若是加上对应的f因为f的值肯定是小于对应回文半径的所以在其回文半径内即使半径进行减小也为回文字符串。所以此时让i加上对应的f到蓝色字符串的开头即可。然后蓝色字符串匹配到l2出自然会结束匹配。
I.Link with Gomoku
题意给定一个n*m的棋盘下五子棋让构造出一个棋局为和棋。
思路按照样例模拟即可。即放四个白子一个黑子下一行放四个黑子一个百子然后找题目要求去后续填充即可。
#includebits/stdc.husing namespace std;
const int N1e55;
typedef long long ll;
typedef pairll,ll pll;
int mod998244353;
const int maxv4e65;void solve()
{ int n,m;cinnm;if(n%2){for(int i1;in-1;i){if(i%2){for(int j1;jm;j){if(j%50) couto;else coutx;}}else{for(int j1;jm;j){if(j%50) coutx;else couto;}}coutendl;}for(int i1;im;i){if(i%2) coutx;else couto;}coutendl;}else{for(int i1;in;i){if(i%2){for(int j1;jm;j){if(j%50) couto;else coutx;}}else{for(int j1;jm;j){if(j%50) coutx;else couto;}}coutendl;}}}int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;t1;cint;while(t--){solve();}system(pause);return 0;
}K.Box #includebits/stdc.husing namespace std;
const int N1e65;
typedef long long ll;
typedef pairll,ll pll;
int mod998244353;
const int maxv4e65;ll dp[N][3];
ll a[N],b[N];void solve()
{ int n;cinn;vectorint pos;for(int i1;in;i){cina[i];}pos.push_back(0);for(int i1;in;i){cinb[i];if(b[i]1) pos.push_back(i);}memset(dp,-0x3f,sizeof dp);if(pos.size()1){cout0endl;return ;}if(pos[1]-10) dp[1][0]a[pos[1]-1];if(pos[1]1n) dp[1][2]a[pos[1]1];dp[1][1]a[pos[1]];for(int i2;ipos.size();i){for(int j0;j3;j){for(int k0;k3;k){if(pos[i-1]k-1pos[i]j-1pos[i]j-1n){dp[i][j]max(dp[i][j],dp[i-1][k]a[pos[i]j-1]);}}}}int xpos.size()-1;coutmax({dp[x][0],dp[x][1],dp[x][2]})endl;
}int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;t1;//cint;while(t--){solve();}system(pause);return 0;
}