@iamtts
2017-04-22T22:28:39.000000Z
字数 4245
阅读 996
1.I a b 转换a位到b位的数字(0-1,1-0)
2. Q a 查询第a位数字
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int bit[100005],n;
char raw[100005];
int lowbit(int x)
{
return x&(-x);
}
void add(int p,int x)
{
while (p<=n)
{
bit[p]+=x;
p+=lowbit(p);
}
}
int sum(int p)
{
int s=0;
while (p)
{
s+=bit[p];
p-=lowbit(p);
}
return s;
}
int main()
{
int t,Case=0;
scanf("%d",&t);
while (t--)
{
memset(bit,0,sizeof(bit));
scanf("%s",raw);
n=strlen(raw);
int tt;
scanf("%d",&tt);
printf("Case %d:\n",++Case);
while(tt--)
{
char ch;
getchar();
scanf("%c",&ch);
if (ch=='I')
{
int a,b;
scanf(" %d %d",&a,&b);
add(a,1);
add(b+1,-1);
}
else
{
int a;
scanf(" %d",&a);
printf("%d\n",sum(a)%2?1^(raw[a-1]-'0'):(raw[a-1]-'0'));
}
}
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#define pi acos(0.0)*2
#define maxn 100005
#define INF 1<<30
using namespace std;
int n,q;
int a[100005];
int main()
{
int t,Case=0;
scanf("%d",&t);
while (t--)
{
scanf("%d%d",&n,&q);
printf("Case %d:\n",++Case);
for (int i=0;i<n;i++) scanf("%d",&a[i]);
while (q--)
{
int x,y;
scanf("%d%d",&x,&y);
int ans=upper_bound(a,a+n,y)-lower_bound(a,a+n,x);
printf("%d\n",ans);
}
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define pi acos(0.0)*2
using namespace std;
int main()
{
int t,Case=0;
scanf("%d",&t);
while (t--)
{
double R,n,r;
scanf("%lf%lf",&R,&n);
double a=sin(pi/n);
r=R*a/(1+a);
printf("Case %d: %lf\n",++Case,r);
}
return 0;
}
dp[i][0]=min(dp[i-1][1]+a[i-1][0],dp[i-1][2]+a[i-1][0])
dp[i][1]=min(dp[i-1][0]+a[i-1][1],dp[i-1][2]+a[i-1][1])
dp[i][2]=min(dp[i-1][0]+a[i-1][2],dp[i-1][1]+a[i-1][2])
0,1,2代表不同颜色
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define pi acos(0.0)*2
#define maxn 100005
#define INF 1<<30
using namespace std;
int a[20][3],n,dp[21][3];
int ans;
int main()
{
int t,Case=0;
scanf("%d",&t);
while (t--)
{
ans=INF;
scanf("%d",&n);
for (int i=0;i<n;i++)
{
for (int j=0;j<3;j++)
scanf("%d",&a[i][j]);
}
for (int i=1;i<=n;i++)
{
dp[i][1]=min(dp[i-1][0]+a[i-1][1],dp[i-1][2]+a[i-1][1]);
dp[i][0]=min(dp[i-1][1]+a[i-1][0],dp[i-1][2]+a[i-1][0]);
dp[i][2]=min(dp[i-1][0]+a[i-1][2],dp[i-1][1]+a[i-1][2]);
}
printf("Case %d: %d\n",++Case,min(dp[n][2],min(dp[n][1],dp[n][0])));
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define pi acos(0.0)*2
#define maxn 100005
#define INF 100005
using namespace std;
int n,dat[4*maxn];
void init(int n_)
{
n=1;
while (n<n_) n*=2;
for (int i=0;i<2*n-1;i++) dat[i]=INF;
}
void update(int k,int a)
{
k=n-1+k;
dat[k]=a;
while (k)
{
k=(k-1)/2;
dat[k]=min(dat[k*2+1],dat[k*2+2]);
}
}
int query(int a,int b,int k,int l,int r)
{
if (r<a || l>b) return INF;
if (a<=l && r<=b) return dat[k];
else
{
int vl=query(a,b,2*k+1,l,(l+r)/2);
int vr=query(a,b,2*k+2,(l+r)/2+1,r);
return min(vl,vr);
}
}
int main()
{
int t,Case=0;
scanf("%d",&t);
while (t--)
{
int nn,q;
scanf("%d%d",&nn,&q);
init(nn);
printf("Case %d:\n",++Case);
for (int i=0;i<nn;i++)
{
int x;
scanf("%d",&x);
update(i,x);
}
for (int i=0;i<q;i++)
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",query(a-1,b-1,0,0,n-1));
}
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#define pi acos(0.0)*2
#define maxn 100005
#define INF 1<<30
using namespace std;
struct node
{
int to,cost;
node(int x,int y):to(x),cost(y){}
};
vector<node> G[30005];
int n,pos_1,pos_2,dis;
bool vis[30005];
void dfs(int u,int d)
{
vis[u]=1;
if (d>dis) {dis=d;pos_1=u;}
for (int v=0;v<G[u].size();v++)
{
if (G[u][v].to!=u && !vis[G[u][v].to])
{
dfs(G[u][v].to,d+G[u][v].cost);
}
}
}
int main()
{
int t,Case=0;
scanf("%d",&t);
while (t--)
{
scanf("%d",&n);
dis=-1;
memset(vis,0,sizeof(vis));
for (int i=0;i<=n;i++) G[i].clear();
for (int i=0;i<n-1;i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
G[v].push_back(node(u,w));
G[u].push_back(node(v,w));
}
dfs(0,0);
dis=-1;
memset(vis,0,sizeof(vis));
dfs(pos_1,0);
printf("Case %d: %d\n",++Case,dis);
}
return 0;
}