总结
lls不在的第一天,想他
数学我** 你个 **
1001 题意
fx是一个由c,cx,c/x,csinx,ccosx,c/sinx,c/cosx,c^x由加号拼接的函数,对他求前缀和一样的东西得到sx,给你fx,问sx是否收敛
1001 思路
高数下练习题
sx收敛,则fx趋0,由高数知识知这些都不趋0,只有常数C均为0时才成立。
1001 代码
#include<stack>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#include<deque>
#include<vector>
#include<iostream>
#include<map>
#include<set>
#include<iomanip>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
using namespace std;
ll GCD(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const int inf=0x3f3f3f3f;
string s;
int T;
bool boo;
signed main()
{
#ifndef ONLINE_JUDGE
freopen("IO\\in.txt","r",stdin);
freopen("IO\\out.txt","w",stdout);
clock_t start, end;
start = clock();
#endif
IOS
cin>>T;
while (T--)
{
cin>>s;
boo=false;
for (int i=0;i<s.length();i++)
if (s[i]>'0'&&s[i]<='9') boo=true;
if (boo) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
#ifndef ONLINE_JUDGE
end = clock();
cout << endl << "Runtime: " << (double)(end - start) / CLOCKS_PER_SEC << "s\n";
#endif
}
1002 题意
一颗树,点带权,aij代表i到j路径上不同点权数,需输出所有aij和一个奇怪东西的乘积加和
1002 思路
可以n²跑,暴力就完事了。
1002 代码
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<chrono>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long
//#define double long double
using namespace std;
typedef long long ll;
const int maxn=2505;
const int inf=0x3f3f3f3f;
const int mod1=1e9+7;
const int mod2=1e9+9;
int pow_1[maxn],pow_2[maxn];
ll pow_m(ll a,ll k,ll p) {
ll ans=1;
ll tmp=a%p;
while(k) {
if(k&1)ans=ans*tmp%p;
tmp=tmp*tmp%p;
k>>=1;
}
return ans;
}
int n,m,k;
vector<int>e[maxn];
int val[maxn];
unordered_map<int,int>mp;
int ans1,ans2;
void dfs(int x,int fa){
mp[val[x]]++;
//cout<<"x:"<<x<<"mp:"<<mp.size()<<endl;
ans1+=(mp.size()*pow_1[x-1])%mod1;
ans1%=mod1;
ans2+=(mp.size()*pow_2[x-1])%mod2;
ans2%=mod2;
for(auto y:e[x]){
if(y==fa) continue;
dfs(y,x);
}
int t=mp[val[x]]-1;
mp.erase(val[x]);
if(t)
mp[val[x]]=t;
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++) e[i].clear();
for(int i=2;i<=n;i++){
int t;
cin>>t;
e[t].push_back(i);
e[i].push_back(t);
}
for(int i=1;i<=n;i++){
cin>>val[i];
}
for(int i=1;i<=n;i++){
ans1=ans2=0;
mp.clear();
//cout<<"i:"<<i<<"------------"<<endl;
dfs(i,0);
//cout<<"------------------"<<endl;
cout<<ans1<<' '<<ans2<<endl;
}
}
signed main(){
IOS
#ifndef ONLINE_JUDGE
freopen("IO\\in.txt","r",stdin);
freopen("IO\\out.txt","w",stdout);
#endif
int tn=1;
cin>>tn;
for(int i=0;i<2005;i++){
pow_1[i]=pow_m(19560929,i,mod1);
pow_2[i]=pow_m(19560929,i,mod2);
}
while(tn--){
solve();
}
}
1008 题意
11走到nn,只能右走或下走,一些点被挡住了过不去,问有多少点到不了
1008 思路
光球层上的黑子 14:02:49
我们按行看,首先一个性质,一行里能到达的点和不能到达的点是一个交替排列的若干连续段。比如我们用0表示可达,1表示不可达,那么某行的可达情况应当是00001110000这种类型
光球层上的黑子 14:05:40
我们考虑行的转移,在这一行上初始不可达点是输入中的点,对于这样的点,它会阻挡人从左方走过来,对于他右侧的点,只有从上方可达转移下来的点才能到,如果这个点右侧的某个点x上方也是不可达的,那么这个点x一定也不可达。也就是说初始不可达点可以向右“染色”,就是找到右方最远的pos,使得pos上方为1也就是不可达。之后将这一段全部染为1.
光球层上的黑子 14:08:19
染色操作和找操作应当都可以使用数据结构优化成log,至于答案就是每一行1的个数,区间查询就行。空间受限肯定不可能开O(n)棵树,显然当前这一行答案只与上一行答案有关,所以我们开两颗树,类似01背包的空间优化那样滚动着用应该就可以了。
以上为和carry嘴的做法,结果最后嘴完也是我自己写,那没事了…
注意特判一个情况,我们在一开始需要独立找一下上一行最左的0位置,在这个位置左边是到不了的,这也是一直的wa点。
1008 代码
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<chrono>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
//#define int long long
//#define double long double
using namespace std;
typedef long long ll;
const int maxn=200505;
const int inf=0x3f3f3f3f;
int n,m,k;
vector<int>point[maxn];
struct tree{
int l,r;
ll sum;
int add;
}t1[maxn<<2],t2[maxn<<2];
ll ans;
inline void build(int root,int l,int r,tree *t){
t[root].l=l,t[root].r=r;
t[root].add=-1;
if(l==r){
t[root].sum=0;
return ;
}
int mid=l+r>>1;
build(root<<1,l,mid,t);
build(root<<1|1,mid+1,r,t);
t[root].sum=0;
}
inline void pushdown(int root,tree *t){
if(~t[root].add){
t[root<<1].sum=(t[root<<1].r-t[root<<1].l+1)*t[root].add;
t[root<<1|1].sum=(t[root<<1|1].r-t[root<<1|1].l+1)*t[root].add;
t[root<<1].add=t[root].add;
t[root<<1|1].add=t[root].add;
t[root].add=-1;
}
}
void update(int root,int l,int r,int x,tree *t){
if(l<=t[root].l&&r>=t[root].r){
t[root].sum=x*(t[root].r-t[root].l+1);
t[root].add=x;
return ;
}
pushdown(root,t);
int mid=t[root].l+t[root].r>>1;
if(mid>=l) update(root<<1,l,r,x,t);
if(mid<r) update(root<<1|1,l,r,x,t);
t[root].sum=t[root<<1].sum+t[root<<1|1].sum;
}
int query(int root,int l,int r,tree *t){
if(l<=t[root].l&&r>=t[root].r){
return t[root].sum;
}
pushdown(root,t);
int mid=t[root].l+t[root].r>>1;
int ans=0;
if (l<=mid) ans+=query(root<<1,l,r,t);
if (r>mid) ans+=query(root<<1|1,l,r,t);
return ans;
}
int q_pos(int root,int x,tree *t){
if(x>m) return m+1;
if(t[root].sum==t[root].r-t[root].l+1)
return inf;
if(t[root].l==t[root].r){
if(t[root].sum==0) return t[root].l;
return inf;
}
pushdown(root,t);
int mid=t[root].l+t[root].r>>1;
int ans=inf;
if (x<=mid) ans=min(ans,q_pos(root<<1,x,t));
if(ans==inf)
ans=min(ans,q_pos(root<<1|1,x,t));
return ans;
}
inline void change(int last,int now){
if(now&1){
update(1,1,m,0,t2);
if(now>1){
int p=q_pos(1,1,t1);
p=min(p-1,m);
update(1,1,p,1,t2);
}
for(auto x:point[now]){
int pos=q_pos(1,x+1,t1);
pos=min(pos-1,m);
update(1,x,pos,1,t2);
}
ans-=query(1,1,m,t2);
}
else{
update(1,1,m,0,t1);
int p=q_pos(1,1,t2);
p=min(p-1,m);
update(1,1,p,1,t1);
for(auto x:point[now]){
int pos=q_pos(1,x+1,t2);
pos=min(pos-1,m);
update(1,x,pos,1,t1);
}
ans-=query(1,1,m,t1);
}
}
void solve(){
scanf("%d%d%d",&n,&m,&k);
ans=1ll*n*m;
for(int i=1;i<=n;i++) point[i].clear();
while(k--){
int a,b;
scanf("%d%d",&a,&b);
point[a].emplace_back(b);
}
build(1,1,m,t1),build(1,1,m,t2);
update(1,1,m,1,t1);
for(int i=1;i<=n;i++){
change(i-1,i);
}
printf("%lld\n",ans);
/* for(int i=1;i<=m;i++)
cout<<query(1,i,i,t1)<<' ';
cout<<endl;
update(1,5,8,1,t1);update(1,11,12,1,t1);
for(int i=1;i<=m;i++)
cout<<query(1,i,i,t1)<<' ';
cout<<endl;
cout<<q_sum(1,1,12,t1)<<endl;
for(int i=1;i<=m;i++)
cout<<q_pos(1,i,t1)<<' ';
cout<<endl; */
}
signed main(){
#ifndef ONLINE_JUDGE
freopen("IO\\in.txt","r",stdin);
freopen("IO\\out.txt","w",stdout);
#endif
int tn=1;
scanf("%d",&tn);
while(tn--){
solve();
}
}
1009 题意
给30*100图,里面6个点阵画,让你输出他们的左右边界。
1009 思路
模拟题,我们二维投影到一维,右侧五个点阵画保证连续,扫一下就行,左侧汉字不一定连续,所以先右扫,再左扫。
1009 代码
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<chrono>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
//#define int long long
//#define double long double
using namespace std;
typedef long long ll;
const int maxn=400505;
const int inf=0x3f3f3f3f;
int n,m,k;
int a[105];
void solve(){
memset(a,0,sizeof a);
for(int i=1;i<=30;i++){
for(int j=1;j<=100;j++){
char ch;
cin>>ch;
if(ch=='#')
a[j]++;
}
}
vector<pair<int,int> >v;
int l,r;
bool bl=0;
int p=100;
while(p&&v.size()<6){
if(a[p]){
if(!bl){
bl=1;
r=p;
}
}
else{
if(bl){
bl=0;
l=p;
v.push_back({l+1,r});
}
bl=0;
}
p--;
}
for(int i=1;i<=p;i++){
if(a[i]){
l=i;
break;
}
}
for(int i=p;i;i--){
if(a[i]){
r=i;
break;
}
}
v.push_back({l,r});
reverse(v.begin(),v.end());
for(auto p:v)
cout<<p.first<<' '<<p.second<<endl;
}
signed main(){
IOS
#ifndef ONLINE_JUDGE
freopen("IO\\in.txt","r",stdin);
freopen("IO\\out.txt","w",stdout);
#endif
int tn=1;
cin>>tn;
for(int i=1;i<=tn;i++){
cout<<"Case #"<<i<<":"<<endl;
solve();
}
}
未完待续
E 题意
E 思路
E 代码
在这里插入代码片