一名大三older 希望能帮助大一萌新。。。加油 xiandianer!!!!;

xdoj 1260 (B) 水题 用了一下STL (好长啊。。。)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
const int N=;
struct T{
string suj;
double p;
bool operator <(const T& b) const {
return suj<b.suj;
}
};
map <T,int> mapp;
int n;
double f (int x) {
if (x<=) return 0.0;
if (x<=) return 1.0;
if (x<=) return 1.5;
if (x<=) return 1.7;
if (x<=) return 2.0;
if (x<=) return 2.3;
if (x<=) return 2.7;
if (x<=) return 3.0;
if (x<=) return 3.3;
if (x<=) return 3.7;
return 4.0;
}
int main ()
{
cin>>n;
map<T,int>::iterator it;
for (int i=;i<=n;i++) {
T temp;
int w;
cin>>temp.suj>>temp.p>>w;
if (mapp[temp]<w)
mapp[temp]=w;
}
it=mapp.begin();
double sum=0.0;
double k=0.0;
double nn=0.0;
while (it!=mapp.end()) {
sum+=(it->first.p)*(it->second);
k+=(it->first.p)*f(it->second);
nn+=it->first.p;
it++;
}
printf ("%.1lf\n%.2lf\n",sum/nn,k/nn);
return ;
}

xdoj 1255 (C) 水题 不明白为什么不加getchar() 会GG;

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
char* str="0123456789ABCDEF";
int main ()
{
int x,y,z;
while (~scanf("(%d, %d, %d)",&x,&y,&z)) {
char s[];
s[]=str[x/];
s[]=str[x%];
s[]=str[y/];
s[]=str[y%];
s[]=str[z/];
s[]=str[z%];
s[]='\0';
cout<<"#"<<s<<endl;
getchar();
}
return ;
}

xdoj 1265(D) 取余找循环节呗。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int mod=;
struct T {
int a;
int b;
};
T t[N];
int p[N];
int A,B,C;
int n,k;
int mycmp (T aa,T bb) {
return aa.a>bb.a;
}
int main ()
{
int nn;
scanf ("%d",&nn);
while (nn--) {
scanf ("%d %d %d",&A,&B,&C);
memset (p,,sizeof(p));
int i=;
t[].a=A;
p[A]=;
while () {
t[i+].a=(t[i].a*B+C)%mod;
if (p[t[i+].a])
break;
else
p[t[i+].a]=i+;
i++;
}
int x1=p[t[i+].a];
int x2=i;
int num=x2-x1+;
scanf ("%d %d",&n,&k);
int times=(n-x1+)/num;
for (i=;i<=x2;i++) {
if (i<x1) t[i].b=;
else if (i<=x1+(n-x1+)%num)
t[i].b=times+;
else
t[i].b=times;
}
sort (t+,t++x2,mycmp);
i=;
while () {
if (p[t[i].a]>n) {i++; continue;}
if (k-t[i].b<=) break;
else k-=t[i].b;
i++;
}
printf ("%d\n",t[i].a);
}
return ;
}

xdoj 1262(E) 找A前后Q数目相乘

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const int N=1e5+;
char str[N];
int main ()
{
scanf ("%s",str);
int len=strlen(str);
LL n1=;
for (int i=;i<len;i++) {
if (str[i]=='Q')
n1++;
}
LL n2=;
LL sum=;
for (int i=;i<len;i++) {
if (str[i]=='Q')
n2++;
if (str[i]=='A')
sum+=n2*(n1-n2);
}
printf ("%lld\n",sum);
return ;
}

xdoj  1264(F) 找一下规律 发现数据按照二进制递增的

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long LL;
bool a[];
int main ()
{
LL n;
while (~scanf ("%lld",&n)) {
memset (a,,sizeof(a));
int i=;
while (n) {
if (n&) a[i]=;
n=n>>;
i++;
}
for (int i=;i>=;i--) {
if (a[i])
printf ("R");
else
printf ("G");
}
printf ("\n");
}
return ;
}

xdoj 1261(G)  开始用图做的 GG了最后用的并查集

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int N=1e6+;
int p[N];
int f[N];
int n,m;
int _find(int x) {
if (x!=f[x])
f[x]=_find(f[x]);
return f[x];
}
int main ()
{
while (~scanf ("%d %d",&n,&m)) {
for (int i=;i<=n;i++)
f[i]=i;
memset(p,,sizeof(p));
for (int i=;i<=m;i++) {
int op,a,b;
scanf ("%d %d %d",&op,&a,&b);
if (op==) {
int x1=_find(a);
int x2=_find(b);
if (x1==x2||p[x1]==x2) continue;
if (!p[x1]&&!p[x2]) {
p[x1]=x2;
p[x2]=x1;
}
else if (!p[x1]&&p[x2]) f[x1]=p[x2];
else if (!p[x2]&&p[x1]) f[x2]=p[x1];
else {f[x2]=p[x1]; f[p[x2]]=x1;}
//for (int i=1;i<=n;i++)
// cout<<_find(i)<<" "<<p[i]<<endl;
}
else {
int x1=_find(a);
int x2=_find(b);
if (x1==x2)
printf ("In the same category.\n");
else if (p[x1]==x2)
printf ("In different category.\n");
else
printf ("Not sure yet.\n");
}
}
}
return ;
}

xdoj  1254(H) 大整数减法 基本功

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
const int N=;
int a[N];
int b[N];
int x1[N];
int x2[N];
string s1,s2;
int cmp (int a[],int b[]) {
for (int i=;i>=;i--) {
if (a[i]>b[i]) return ;
if (a[i]<b[i]) return -;
}
return ;
}
void f (int x[]) {
memset(x1,,sizeof(x1));
memset(x2,,sizeof(x2));
int j=;
for (int i=s1.size()-;i>=;i--)
x1[j++]=s1[i]-'';
j=;
for (int i=s2.size()-;i>=;i--)
x2[j++]=s2[i]-'';
for (int i=;i<s1.size();i++) {
if (x1[i]<x2[i]) {
j=i;
while (x1[j+]==) {
x1[j+]=;
j++;
}
x1[j+]--;
x1[i]+=;
}
x[i]=(x1[i]-=x2[i]);
}
return ;
}
int main ()
{
cin>>s2>>s1;
f(a);
cin>>s2>>s1;
f(b);
if (cmp(a,b)>)
printf ("Ting\n");
else if (cmp(a,b)==)
printf ("Excellent\n");
else
printf ("Yu\n");
return ;
}

xdoj 1257 (I) 曼哈顿距离 我也是百度的。。。哈哈哈

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
int T,n;
ll a1,a2,b1,b2;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
a1=b1=INF,a2=b2=-INF;
for(int i=;i<n;i++)
{
ll x,y;
scanf ("%lld %lld",&x,&y);
a1=min(a1,x+y),a2=max(a2,x+y);
b1=min(b1,x-y),b2=max(b2,x-y);
}
ll ans=max(a2-a1,b2-b1);
printf("%lld\n",ans);
}
return ;
}

xdoj 1250 (J) 好吧这道题我想了好久。。一天?/ 最后感谢formilk的i提示 用的先序遍历 。。居然过了。但应该不是最好的解法

#include<cstdio>
#include<algorithm>
using namespace std;
const int N=5e6+;
struct T {
int x;
int y;
};
T k[];
T s[*N];
int ss;
int t;
int n_max;
int a,b,c,d,n,m;
void fare (int a,int b,int c,int d) {
if (b+d>n_max) return ;
fare (a,b,a+c,b+d);
k[++t].x=(a+c);
k[t].y=(b+d);
fare (a+c,b+d,c,d);
return ;
}
int gcd (int x,int y) {
return !y?x:gcd(y,x%y);
}
void f(int& x,int& y ) {
int p=gcd (x,y);
x=x/p;
y=y/p;
return ;
}
int main ()
{
int Q;
scanf ("%d",&Q);
while (Q--) {
scanf ("%d %d %d %d %d %d",&a,&b,&c,&d,&n,&m);
ss=;
f(a,b); T t1={a,b};
f(c,d); T t2={c,d};
n_max=max(b,d);
t=;
k[t].x=; k[t].y=;
fare (,,,);
k[++t].x=;k[t].y=;
int i;
for (i=;;i++) if (k[i].x==t2.x&&k[i].y==t2.y) break;
for (;;i--) {
s[++ss]=k[i];
if (k[i].x==t1.x&&k[i].y==t1.y) break;
}
int nn=;
while (){
t1=s[ss--];
nn++;
if (nn==n+) break;
if (ss==) break;
t2=s[ss];
while () {
int x=t1.x+t2.x;
int y=t1.y+t2.y;
f(x,y);
if (y<=m) {
t2.x=x; t2.y=y;
s[++ss]=t2;
}
else
break;
}
}
if (nn==n+&&!(t1.x==c&&t1.y==d))
printf ("%d %d\n",t1.x,t1.y);
else
printf ("-1\n");
}
return ;
}

有点匆忙  。。。还有作业啊 欢迎交流QQ-821474143

05-08 08:27