CF problem solution blog: https://codeforces.com/blog/entry/69791?tdsourcetag=s_pcqq_aiomsg
Replenishment of ...
Meaning of the questions:
To a sequence, wherein a selected few number satisfying a divisor of the entire sequence can be selected. Numbers by the selected minimum number.
Ideas:
Violence enumerate all combinations of elements (title in value is relatively small).
code:
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1e9+7; const int maxn = 108; int a[maxn]; int cnt; bool vis[maxn]; bitset<101> bs; int main(){ int n; scanf("%d",&n); for(int i=1; i<=n; i++){ scanf("%d",a+i); } sort(a+1,a+1+n); int ans=0; int flag=0; bs.reset(); for(int i=1; i<=n; i++){ flag=0; for(int j=i; j<=n; j++){ if(a[j]%a[i]==0 && !bs[j]){ bs[j] = 1; flag = 1; } } if(flag){ ans++; } if(bs.count()==n){ printf("%d\n", ans); return 0; } } printf("%d\n", ans); }
Meaning of the questions:
N you lamp in the initial state (on or off), and for each lamp is given two values a, b; a representative of fast off state of the switching cycle, b represents the first switching time. Q. At some point, the number of bulbs lit simultaneously, and up to how much.
Ideas:
Violence: 1e5 enumeration of all time, then the statistical maximum.
code:
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1e9+7; const int maxn = 108; char s[maxn]; int a[maxn],b[maxn],c[maxn]; bitset<maxn> bs; int main(){ int n; scanf("%d",&n); scanf("%s",s+1); bs.reset(); for(int i=1; i<=n; i++){ bs[i] = s[i]-'0'; } for(int i=1; i<=n; i++){ scanf("%d%d",a+i,b+i); } int ans=0; for(int j=0; j<=30000; j++){ for(int i=1; i<=n; i++){ if( j>=b[i] && ((j-b[i])%a[i] )==0 ) { bs[i] = (int)bs[i]^1; } } ans = max(ans,(int)bs.count()); } printf("%d\n", ans); }
Meaning of the questions:
A given sequence, then select two sequences, two sequences to ensure itself (non-decreasing), and finally to ensure that the selected 12 sequence also showed a (non-decreasing) arrayed
Ideas:
A non-descending order, sequence. It is easy to think of monotonous stack. So we start and monotonous side queue to find out all eligible 1. 1 but also to the queue for processing, i.e., to find the first element 2, is greater than all the queues of all of the first element 2 out of the stack,
This would address 12 is also in a non-descending order. For the case where no solution that is determined for the first time after the handle 1 if the sequence remaining in a non-decreasing can.
code:
#include <cstdio> #include <queue> #include <iostream> #include <algorithm> #include <stack> #include <string> #include <cstring> using namespace std; const int maxn =2e5+7; const int inf = 0x3f3f3f3f; char arr[maxn]; stack<int>a; int top; struct node{ int val; int cur; }s[maxn]; void init(){ top = 0; s[0].val = -1; s[0].cur = -1; while(!a.empty()) a.pop(); } int main(){ int T; scanf("%d",&T); while(T--){ int n,m; scanf("%d",&n); scanf("%s",arr); init(); for(int i=0;i<n;i++){ while(s[top].val>arr[i]-'0'){ top--; } s[++top].val = arr[i]-'0'; s[top].cur = i; } int first=-1;//最后最小位置 int cu=1; for(int i =0;i<n;i++){ if(s[cu].cur==i) cu++; else{ first = i; break; } } while(s[top].val>arr[first]-'0'&&first!=-1){ top--; } cu = 1; for(int i =0;i<n;i++){ if(s[cu].cur==i&&cu<=top) { //找到第一个最小位置 cu++; }else a.push(arr[i]-'0'); } int flag = 0; if(!a.empty()){ int now = a.top(); a.pop(); int len = a.size(); for(int i=0;i<len;i++){ int tmp = a.top(); a.pop(); if(now<tmp) { flag = 1; break; } now = tmp; } } if(flag){ puts("-"); }else{ cu = 1; for(int i =0;i<n;i++){ if(i==s[cu].cur&&cu<=top){ printf("1"); cu++; }else printf("2"); } puts(""); } } }