南京理工大学第八届校赛题目题解(部分)
https://icpc.njust.edu.cn/Contest/749/rank/、
a偷吃糖果
思路:读入的时候相同的字母合并成一个字母。最后比较一下。
/* *********************************************** Author :guanjun Created Time :2016/4/17 12:37:02 File Name :njusta.cpp ************************************************ */ #include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <iomanip> #include <list> #include <deque> #include <stack> #define ull unsigned long long #define ll long long #define mod 90001 #define INF 0x3f3f3f3f #define maxn 10010 #define cle(a) memset(a,0,sizeof(a)) const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; priority_queue<int,vector<int>,greater<int> >pq; struct Node{ int x,y; }; int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif //freopen("out.txt","w",stdout); int T; string s,t; cin>>T; while(T--){ cin>>s>>t; string ss=""; ss+=s[0]; string tt=""; tt+=t[0]; int tmp=0; for(int i=1;i<s.size();i++){ if(s[i]==ss[tmp])continue; tmp++; ss+=s[i]; } tmp=0; for(int i=1;i<t.size();i++){ if(t[i]==tt[tmp])continue; tmp++; tt+=t[i]; } //cout<<ss<<" "<<tt<<endl; if(ss==tt)puts("Yes"); else puts("No"); } return 0; }
c. count_prime
这是hduoj上的原题。容斥基础题。
#include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <iomanip> #include <list> #include <deque> #include <stack> #define ull unsigned long long #define ll long long #define mod 90001 #define INF 0x3f3f3f3f #define maxn 10000+10 #define cle(a) memset(a,0,sizeof(a)) const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; bool cmp(int a,int b){ return a>b; } ll a,b,n; ll solve(){ ll sum=0; vector<ll>v; for(int i=2;i*i<=n;i++) if(n%i==0){ v.push_back(i); while(n%i==0)n/=i; } if(n>1)v.push_back(n); for(ll st=1;st<(1<<(v.size()));++st){//0 1 ll bits=0,mult=1; for(int i=0;i<(int)v.size();++i){ if(st&(1<<i)){ ++bits; mult*=v[i]; } } ll cur=b/mult-a/mult; if(a%mult==0)cur++; if(bits&1)sum+=cur; else sum-=cur; } return b-a-sum+1; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif //freopen("out.txt","w",stdout); int t; cin>>t; for(int i=1;i<=t;i++){ scanf("%I64d %I64d %I64d",&a,&b,&n); printf("%lld\n",solve()); } return 0; }
f.sequence
暴力一发
#include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <iomanip> #include <list> #include <deque> #include <stack> #define ull unsigned long long #define ll long long #define mod 90001 #define INF 0x3f3f3f3f #define maxn 10010 #define cle(a) memset(a,0,sizeof(a)) const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; priority_queue<int,vector<int>,greater<int> >pq; struct Node{ int x,y; }; bool cmp(int a,int b){ return a>b; } int dp[maxn],n,x,mark; int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif //freopen("out.txt","w",stdout); int t; cin>>t; while(t--){ cin>>n; int m=1; dp[1]=-INF; for(int i=1;i<=n;i++){ scanf("%d",&x); mark=0; for(int j=1;j<=m;j++){ if(dp[j]<=x){ dp[j]=x; mark=1; break; } } if(mark==0)dp[++m]=x; } printf("%d\n",m); } return 0; }
h.谁才是最强战舰!
博弈 模板题
#include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <iomanip> #include <list> #include <deque> #include <stack> #define ull unsigned long long #define ll long long #define mod 90001 #define INF 0x3f3f3f3f #define maxn 10010 #define cle(a) memset(a,0,sizeof(a)) const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; priority_queue<int,vector<int>,greater<int> >pq; int n; bool Calculate() { int i,x,xor_sum=0; bool flag=1; cin>>n; for(i=1;i<=n;i++) { scanf("%d",&x); if(x^1) flag=0; xor_sum^=x; } if(flag)return !xor_sum; else return xor_sum; } int main(){ #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif //freopen("out.txt","w",stdout); int T,i; for(cin>>T;T;T--) { if(Calculate())puts("Yamato_Saikou!"); else puts("Meidikeji_Shijiediyi!"); } return 0; }
j.water1
#include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <iomanip> #include <list> #include <deque> #include <stack> #define ull unsigned long long #define ll long long #define mod 90001 #define INF 0x3f3f3f3f #define maxn 100100 #define cle(a) memset(a,0,sizeof(a)) const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; priority_queue<int,vector<int>,greater<int> >pq; bool cmp(int a,int b){ return a>b; } int a[maxn]; int b[maxn]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif //freopen("out.txt","w",stdout); int n; while(scanf("%d",&n)!=EOF){ if(n==0){printf("%d\n",1);continue;} int Max=-1; for(int i=1;i<=n;i++){ scanf("%d%d",&b[i],&a[i]); Max=max(b[i],Max); } ll ans=0; Max++; //cout<<Max<<endl; for(int i=1;i<=n;i++){ ans+=a[i]*(Max-b[i]); } printf("%lld\n",ans); } return 0; }
还有些 题目不会做。以后要补 官方题解https://icpc.njust.edu.cn/gist/comzyh/a36db955-1113-4fa2-9000-2beb0bdc7201/
原文地址:http://www.cnblogs.com/pk28/
与有肝胆人共事,从无字句处读书。
欢迎关注公众号:
欢迎关注公众号: